告知 CCAction 何时完成运行



我希望能够在动画序列完成运行时停止所有操作,我该怎么做?现在我有:

CCAnimation *spinAnim = [CCAnimation
                                 animationWithSpriteFrames:spinAnimFrames delay:0.1125f];
        self.spinAction = [CCAnimate actionWithAnimation:spinAnim];

然后以后:

[self.character runAction:self.spinAction];

那么我怎么能知道旋转动作已经完成呢?

您可以使用序列

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 !
}

您可以使用 CCCallFunc 安排回调,方法是将其添加为一系列操作中的最后一个操作,如下所示:

[self.character runAction:[CCSequence actions:self.spinAction,[CCCallFunc actionWithTarget:self selector:@selector(stopAllActions)],nil]];

希望对您有所帮助!

我只是用这样的块意识到了这一点:

(在 .h 上)

typedef void(^actionTerminated)(void);

(在 .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..
}];

最新更新