checking if an SKNode is running a SKAction

谁说我不能喝 提交于 2019-12-21 09:29:17

问题


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.


回答1:


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.




回答2:


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];
}


来源:https://stackoverflow.com/questions/19009577/checking-if-an-sknode-is-running-a-skaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!