首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >CCAnimation工作不正常

CCAnimation工作不正常
EN

Stack Overflow用户
提问于 2013-09-06 05:10:30
回答 1查看 129关注 0票数 0

我需要帮助

我正在开发一个简单的2d游戏,角色在游戏中左右行走。

我使用的是运动鞋操纵杆和我应用CCAnimation的6帧步行动画。

我的问题是,当我的动画被调用从操纵杆更新方法,动画启动时,只有我释放左或右按钮从左操纵杆.在我看来我错过了一些简单的东西,但我想不出.

代码语言:javascript
运行
复制
-(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];
}

有人吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-06 10:59:13

你的问题是你启动动画太频繁了。大约每秒钟60次,如果你的fps是60。因此,您正试图在节点上的每个滴答上运行操作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18650310

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档