Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if SKAction is running

How do I check if a SKAction has finished its animation?

I need to check if my action has already finished or is still performing its action. After that I want to create a boolean to avoid multiple actions during the main action.

SKAction *lionJumpActionComplete = [lionNode actionForKey:@"lionIsJumping"];
    lionJumpActionComplete = [SKAction sequence: @[lionJumpActionUp, lionJumpActionFly, lionJumpActionDown, lionJumpActionPause]];

    if (lionJumpActionComplete) {
        return;
    }

    [lionNode runAction:lionJumpActionComplete withKey:@"lionIsJumping"];
like image 711
David P Avatar asked Jan 12 '23 04:01

David P


1 Answers

If this is the only action running on your node, you can check this using:

if (!lionNode.hasActions) { // check if no actions are running on this node
   // action code here
}

Alternatively, you can set your boolean in a completion block that gets called after the action runs and completes:

[lionNode runAction:[SKAction sequence: @[lionJumpActionUp, lionJumpActionFly, lionJumpActionDown, lionJumpActionPause]] completion:^{
    BOOL isActionCompleted = YES;
}];
like image 200
Batalia Avatar answered Jan 17 '23 18:01

Batalia