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"];
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;
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With