2011-09-04 123 views

回答

1

您可以随时添加一个方法来指示何时结束该方法,然后切换某些BOOL或类似的东西,以表明它没有运行,并投入了启动方法来切换BOOL表明它开始:

id actionMove = [CCMoveTo actionWithDuration:actualDuration 
position:ccp(-target.contentSize.width/2, actualY)]; 

id actionMoveDone = [CCCallFuncN actionWithTarget:self 
selector:@selector(spriteMoveFinished:)]; 

id actionMoveStarted = [CCCallFuncN actionWithTarget:self 
selector:@selector(spriteMoveStarted:)]; 

[target runAction:[CCSequence actions:actionMoveStarted, actionMove, actionMoveDone, nil]]; 

here.

改性在两种@selector方法:

-(void) spriteMoveStarted:(id)sender { 
    ccMoveByIsRunning = YES; 
} 

和:

-(void) spriteMoveFinished:(id)sender { 
    ccMoveByIsRunning = NO; 
} 

其中ccmoveByIsRunning是我指的是BOOL。

编辑:正如xus指出的那样,您应该不会这样做,而应该使用其他人指出的[self numberOfRunningActions]

+0

这是一个丑陋劈,[自numberOfRunningActions]应该使用(如下面注释) – xus

+0

@xus : 好点子。我的坏,我不能删除答案,因为他已经接受了,但我指出了我的错误,谢谢! – Dair

6

您可以在任何CCNode使用[self numberOfRunningActions]。对你来说,这听起来像你想知道是否有任何简单的运行或不动作,所以它不是一个大问题,以知道确切的数字事前。

5

我们可以很容易地检查是否采取具体行动,通过使用getActionByTag方法和action.tag性能运行。 没有必要引进CCCallFuncN回调或计数numberOfRunningActions

实施例。

在我们的应用程序中,重要的是让jumpAction在执行另一个跳转之前完成。为了防止已经运行的跳跃行动期间触发另一跳跃 代码的临界跳跃部分被保护为如下:

#define JUMP_ACTION_TAG 1001 

-(void)jump { 
    // check if the action with tag JUMP_ACTION_TAG is running: 
    CCAction *action = [sprite getActionByTag:JUMP_ACTION_TAG]; 

    if(!action) // if action is not running execute the section below: 
    { 
     // create jumpAction: 
     CCJumpBy *jumpAction = [CCJumpBy actionWithDuration:jumpDuration position:ccp(0,0) height:jumpHeight jumps:1]; 

     // assign tag JUMP_ACTION_TAG to the jumpAction: 
     jumpAction.tag = JUMP_ACTION_TAG; 

     [sprite runAction:jumpAction]; // run the action 
    } 
} 
+0

感谢您使用这种检查方法来查看某个操作是否正在运行。我的成千上万行代码的应用程序有一个巨大的故障,最终由您的代码中的方法修复。谢谢。 –

相关问题