Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

checking if an SKNode is running a SKAction

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.

like image 698
user2796283 Avatar asked Sep 25 '13 15:09

user2796283


2 Answers

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];
}
like image 74
Indi Avatar answered Oct 17 '22 16:10

Indi


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.

like image 26
Matt Avatar answered Oct 17 '22 16:10

Matt