2012-08-17 51 views
1

我想創建一個工具欄(最初隱藏)與項目可以拖動。如果點擊一個按鈕,工具欄將出現按鈕(就像鍵盤動畫一樣)。我只是想問一下如何在cocos2d中做到這一點。滑入和滑出動畫像鍵盤在cocos2d

感謝您的迴應!

回答

1

我用這個代碼抽屜打開和關閉。

-(void)showMyCocos2DDrawer 
{ 
    CGSize s = [[CCDirector sharedDirector] winSize]; 

    self.position = ccp(-s.width,0.0f); //do this in ur init method :) 

    CGPoint pos =ccp(0.0f, 0.0f); 

    id moveTo = [CCMoveTo actionWithDuration:0.5f position:pos]; 
    id calFun = [CCCallFunc actionWithTarget:self selector:@selector(animDone)]; 
    id seq = [CCSequence actions:moveTo, calFun, nil]; 

    [self runAction:seq]; 
} 



-(void)hideCocos2DDrawer 
{ 
    CGSize s = [[CCDirector sharedDirector] winSize]; 

    CGPoint pos =ccp(-s.width, 0.0f); 

    id moveTo = [CCMoveTo actionWithDuration:0.3f position:pos]; 
    id calFun = [CCCallFunc actionWithTarget:self selector:@selector(goBack)]; 
    id seq = [CCSequence actions:moveTo, calFun, nil]; 

    [self runAction:seq]; 
} 

-(void) animDone 
{ 
//write in code here.. 
} 

-(void)goBack 
{ 
//write out code here.. 
} 
+0

謝謝!我會試試這個。 – MiuMiu 2012-08-17 09:26:17