我希望能够在动画序列完成运行时停止所有动作,我该怎么做?现在我有:
CCAnimation *spinAnim = [CCAnimation
animationWithSpriteFrames:spinAnimFrames delay:0.1125f];
self.spinAction = [CCAnimate actionWithAnimation:spinAnim];
然后再说:
[self.character runAction:self.spinAction];
那么我怎么能告诉旋转动作已经完成?
答案 0 :(得分:3)
您可以使用序列
CCCallFunc *callMe = [CCCallFunc actionWithTarget:self selector:@selector(doneSpin)];
CCSequence *seq = [CCSequence actions:spinAnim,callMe,nil];
self.spinAction = seq;
[self.character runaction:self.spinAction];
以及代码中的其他地方:
-(void) doneSpin {
// spin action done, do whatever here !
}
答案 1 :(得分:0)
您可以使用CCCallFunc安排回调,方法是将其添加为一系列操作中的最后一个操作,如下所示:
[self.character runAction:[CCSequence actions:self.spinAction,[CCCallFunc actionWithTarget:self selector:@selector(stopAllActions)],nil]];
希望它有所帮助!
答案 2 :(得分:0)
我刚刚用这样的块实现了它:
(on .h)
typedef void(^actionTerminated)(void);
(on .m)
-(void) doJump:(float)delay
times:(int)times
actionBlock:(actionTerminated)actionBlock {
// here there is your code, physicsBody adjusts..
id block = [CCActionCallBlock actionWithBlock:^
{
// stop sound effect if there was
actionBlock();
}];
actionSequence = [CCActionSequence actionWithArray:@[self.action,block]];
[self.sprite runAction:actionSequence];
}
// when you call do jump :
[self doJump:0.45 times:1 actionBlock^{
// here jump action is terminated,do whatever you want..
}];