2
我有一个包含三个动画的CCSprite:空闲,走路和攻击。我想根据精灵是否在移动(如果操纵杆正在使用)在闲置和走路之间切换。所有这些都很好。 对于攻击性动画,我希望它运行一次,然后在完成时返回到上一个动画(例如:空闲),如何检测动画何时完成?Cocos2d - 改变动画结束后的动画
感谢,
戴夫
我有一个包含三个动画的CCSprite:空闲,走路和攻击。我想根据精灵是否在移动(如果操纵杆正在使用)在闲置和走路之间切换。所有这些都很好。 对于攻击性动画,我希望它运行一次,然后在完成时返回到上一个动画(例如:空闲),如何检测动画何时完成?Cocos2d - 改变动画结束后的动画
感谢,
戴夫
好了,所以这就是我所做的,和它的作品,但我不知道,如果它的正确或最好的办法: 1)存储当前动画。 2)如果当前动画正在攻击,则什么都不做。 3)动画之间切换时,如果新的动画正在攻击中,运行在子画面的序列,所述第二动作是一个回调在回调“onDoneAttacking” 4),更改当前的动画
但这不是很顺利,并且不允许攻击速度很快。
这里是什么样子:
-(void) changeAnimation:(NSString*)name forTime:(int) times {
if(currentAnimation != @"attack")
{
CCFiniteTimeAction *action = [CCAnimate actionWithAnimation:[self animationByName:name]];
CCRepeat *repeatAction = [CCRepeat actionWithAction:action times:1];
if(name == @"attack") {
id doneAttacking = [CCCallFunc actionWithTarget:self selector:@selector(onDoneAttacking)];
[self runAction:[CCSequence actionOne:repeatAction two:doneAttacking]];
}
else {
[self runAction:repeatAction];
}
currentAnimation = name;
}
}
-(void) onDoneAttacking {
currentAnimation = @"idle";
}
只是一个提示,对于像你“currentAnimation”状态使用枚举值。它速度更快,而且你有更少的迷雾:) – tallen11 2012-08-07 23:32:11