我需要帮助
我正在开发一个简单的2d游戏,角色在游戏中左右行走。
我使用的是运动鞋操纵杆和我应用CCAnimation的6帧步行动画。
我的问题是,当我的动画被调用从操纵杆更新方法,动画启动时,只有我释放左或右按钮从左操纵杆.在我看来我错过了一些简单的东西,但我想不出.
-(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];
}有人吗?
发布于 2013-09-06 10:59:13
你的问题是你启动动画太频繁了。大约每秒钟60次,如果你的fps是60。因此,您正试图在节点上的每个滴答上运行操作。
https://stackoverflow.com/questions/18650310
复制相似问题