CCAnimation无法正常工作

时间:2013-09-06 05:10:30

标签: objective-c cocos2d-iphone

我需要帮助

我正在开发一个简单的2D游戏,角色左右摆动。

我正在使用sneakyjoystick和6帧的步行动画,我应用CCAnimation

我遇到的问题是,当我从操纵杆更新方法调用动画时,只有当我从左操纵杆释放左或右按钮时动画才会启动...在我看来,我错过了一些简单的但我可以'弄清楚......

-(void) update:(ccTime)deltaTime
{
    CGPoint scaleVelocity = ccpMult(leftJoystick.velocity, 100);
    CGPoint oldPosition = [self.Bartender position];
    CGPoint newPosition = ccp(self.Bartender.position.x + scaleVelocity.x * deltaTime, self.Bartender.position.y + scaleVelocity.y * deltaTime);


    [self.Bartender setPosition:newPosition];
    if (oldPosition.x > newPosition.x) {

        [self.Bartender stopAllActions];
        self.Bartender.flipX = YES;
        [self GoWalk];

    } else if (oldPosition.x == newPosition.x) {

        // Intentionally do nothing to preserve orientation at start of scene!
        NSLog(@"equal");

    } else {

        [self.Bartender stopAllActions];
        self.Bartender.flipX = NO;
        [self GoWalk];
    }


    /*
     if(oldPosition.x > newPosition.x)
     {
     aChar.flipX = YES;
     }
     else if(aChar.flipX == YES)
     {
     aChar.flipX = NO;
     }

     if(jumpButton.active == YES)
     {
     CCLOG(@"jump pressed");
     }
     if(attackButton.active == YES)
     {
     CCLOG(@"attack pressed");
     }

     [aChar setPosition:newPosition];*/

}


-(void)GoStand
{
    self.StandAnimation = [CCAnimation animation];

    [self.StandAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"AStand1.png"]];
    [self.StandAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"AStand1.png"]];
    [self.StandAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"Walk4.png"]];
    [self.StandAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"AStand1.png"]];
    [self.StandAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"AStand1.png"]];

    id animatedAction = [CCAnimate actionWithDuration:0.8f animation:self.StandAnimation restoreOriginalFrame:NO];
    id repeatAction = [CCRepeatForever actionWithAction:animatedAction];
    [self.Bartender runAction:repeatAction];
}

-(void)GoWalk
{
    self.WalkAnimation = [CCAnimation animation];

    [self.WalkAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"Walk1.png"]];
    [self.WalkAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"Walk2.png"]];
    [self.WalkAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"Walk3.png"]];
    [self.WalkAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"Walk4.png"]];
    [self.WalkAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"Walk5.png"]];
    [self.WalkAnimation addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"Walk6.png"]];

    id animatedAction = [CCAnimate actionWithDuration:0.8f animation:self.WalkAnimation restoreOriginalFrame:NO];
    id repeatAction = [CCRepeatForever actionWithAction:animatedAction];
    [self.Bartender runAction:repeatAction];
}

任何人

1 个答案:

答案 0 :(得分:0)

你的问题是你经常开始动画。如果你的fps为60,则每秒约60次。所以你试图在每个节拍上对你的节点运行动作。