2013-01-11 25 views
0

即時貼在奇怪的問題,即時通訊製作一個box2d遊戲,其中我的角色有不同的動畫步行,跳躍和站立。我在切換這些問題上存在問題。這裏是我的代碼..在Box2D遊戲中更改身體動畫問題

controlLayer.m

-(id)init{  
    self=[super init];  
    screenSize=[[CCDirector sharedDirector]winSize];  
    if(self!=nil){   
     [self initJoystickAndButtons]; 
     [self scheduleUpdate];   
return self; 
    } 
} 



-(void)applyJoystick:(SneakyJoystick *)aJoystick forTimeDelta:(float)deltaTime 
{   
     if(aJoystick.velocity.x > 0.0f) {    
      [level1 walkBunny:(ccTime)aJoystick.velocity.x];   
     }    
    if(aJoystick.velocity.y > 0.0f) {        
      b2Vec2 force; 
      force.Set(0.0f, 150.0f); 
      level1.bunnyBody->ApplyLinearImpulse(force, level1.bunnyBody->GetWorldCenter());     
      [level1 jumpBunny];      
     } 

    if(aJoystick.velocity.x == 0.0f) { 
     [level1 standBunny]; 
     }   
    }  
} 

就像你看到的,我已要求我的性格的三種不同的狀態定義它製作動畫這裏,現在這裏有那些方法?applyJoystick被從我的更新方法調用。

level1Layer.m

-(void)walkBunny:(ccTime)duration{   
    NSLog(@"IN WALK BUNNY"); 
    [animatingCyclist stopAllActions];   
    cyclistAnim = [CCAnimation animation];   
    [cyclistAnim addFrameWithFilename:@"walking-step-2.png"];   
    [cyclistAnim addFrameWithFilename:@"walking-step-3.png"]; 
    [cyclistAnim addFrameWithFilename:@"walking-step-4.png"]; 
    [cyclistAnim addFrameWithFilename:@"walking-step-5.png"]; 
    [cyclistAnim addFrameWithFilename:@"walking-step-6.png"]; 
    [cyclistAnim addFrameWithFilename:@"walking-step-7.png"]; 
    [cyclistAnim addFrameWithFilename:@"walking-step-8.png"]; 
    [cyclistAnim addFrameWithFilename:@"walking-step-9.png"];   
    cyclistAnimationAction = [CCAnimate actionWithDuration:(ccTime)duration             animation:cyclistAnim restoreOriginalFrame:YES];   
    id repeatcyclistAnimation = [CCRepeatForever actionWithAction:cyclistAnimationAction];  
    [animatingCyclist runAction:repeatcyclistAnimation];  

} 

-(void)jumpBunny{  
    NSLog(@"IN JUMP BUNNY"); 
    [animatingCyclist stopAllActions];   
    cyclistAnim = [CCAnimation animation];   
    [cyclistAnim addFrameWithFilename:@"jumping-step-1.png"]; 
    [cyclistAnim addFrameWithFilename:@"jumping-step-2.png"];   
    [cyclistAnim addFrameWithFilename:@"jumping-step-3.png"]; 
    [cyclistAnim addFrameWithFilename:@"jumping-step-4.png"]; 
    [cyclistAnim addFrameWithFilename:@"jumping-step-5.png"]; 
    [cyclistAnim addFrameWithFilename:@"jumping-step-6.png"]; 
    [cyclistAnim addFrameWithFilename:@"jumping-step-7.png"];   
    cyclistAnimationAction = [CCAnimate actionWithDuration:5.5f             animation:cyclistAnim restoreOriginalFrame:YES];  
    [animatingCyclist runAction:cyclistAnimationAction];   

} 

和同爲standBunny ...

問題與此是,我的這些方法被一再呼籲站立和行走該動畫的一個迭代之前它被稱爲再次,所以我的動畫沒有完成,它會顯示動畫的第一張圖片。希望你們都能解決我的問題! :(

回答

0

你停止動畫的全部重新創建它的每一幀例如:

if(aJoystick.velocity.x > 0.0f) {    
      [level1 walkBunny:(ccTime)aJoystick.velocity.x];   
     } 

閱讀此爲:「只要水平速度大於0,停止和重新啓動步行兔子動畫」。

您需要檢查,如果速度狀態發生了改變,從< = 0.0F到> 0.0F,然後才調用walkbunny方法一次。

+0

但一旦我得到速度> 0.0F,我條件將是真實的,walkbunny將被連續調用,h我可以將它設置爲與我的動畫同步調用!? – BaSha