0

私のキャラクターが歩く、ジャンプする、立つのに異なるアニメーションを持つ1つの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];
       }          
    }    
}

ご覧のとおり、ここでアニメーションを定義するキャラクターの 3 つの異なる状態を呼び出しました。これらのメソッドは次のとおりです。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についても同じです...

これに関する問題は、これらのメソッドが立ったり歩いたりするときに繰り返し呼び出され、アニメーションを 1 回繰り返す前に再度呼び出されるため、アニメーションが完了せず、毎回アニメーションの最初の画像が表示されることです。皆さんが私の問題を理解してくれることを願っています! :(

4

1 に答える 1

0

アニメーションを停止して、フレームごとにもう一度作成します。例えば:

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

これを次のように読みます: 「水平方向の速度が 0 より大きい限り、ウサギの歩行アニメーションを停止して再開します」。

速度の状態が <= 0.0f から > 0.0f に変化したかどうかを確認してから、walkbunny メソッドを 1 回だけ呼び出す必要があります。

于 2013-01-11T14:24:43.453 に答える