How can I check whether a SKNode
is already running an action before running an action on it?
I want to be able to do something like...
if (![mySprite isRunningActions]) {
[mySprite runAction:action];
}
If there is no built in way I'm thinking of creating a new BOOL
property for holding the action state.
Look at using named actions using any of the SKAction
key-based methods. So you would instead run your action using the named equivalent to runAction:
which is runAction:withKey:
. If an action with the same key is already running, it is removed before the new one is added. Alternatively, use actionForKey:
to see if an action is already running like you are trying to do now in your code, then removeActionForKey:
to remove it or handle as needed.
Sorry for the late answer, but you can use the sprite method hasActions to check if a sprite is currently running any actions.
if (![mySprite hasActions])
{
[mySprite runAction:action];
}