checking if an SKNode is running a SKAction

2020-07-07 03:39发布

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.

2条回答
看我几分像从前
2楼-- · 2020-07-07 04:18

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.

查看更多
混吃等死
3楼-- · 2020-07-07 04:26

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];
}
查看更多
登录 后发表回答