1

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

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

然后:

[self.character runAction:self.spinAction];

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

4

3 回答 3

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 !

}
于 2013-09-18T03:35:10.543 回答
0

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

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

希望能帮助到你!

于 2013-09-18T03:39:21.447 回答
0

我刚刚用这样的块实现了它:

(在.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..
}];
于 2015-07-10T07:44:02.837 回答