Check if the action is currently completed?

Can I check if there are currently actions in the CCNode class in Cocos2d? I would like to know if it still works CCMoveByor not.

+5
source share
3 answers

You can always add a method to indicate when the method is finished, and then switch BOOL or something similar to indicate that it is not running, and place the start method to switch BOOL to indicate that it is running:

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]];

Changed from here.

In two @selector methods:

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

and

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

where ccmoveByIsRunning is the BOOL I'm talking about.

. xus, , [self numberOfRunningActions], .

+1

[self numberOfRunningActions] CCNode. , , - , .

+6

, getActionByTag action.tag. CCCallFuncN numberOfRunningActions.

.

In our application, it is important that jumpAction be completed before another transition is completed. To prevent another jump from starting during the already running transition action, the critical transition section of the code is protected as follows:

#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
    }
}
+5
source

All Articles