Search code examples
swift3sprite-kitskactionsknode

Check if SKNode has a certain action running


I have a SKNode that is running different actions. Depending on the running action I want to trigger other behaviours. For that I would need to find out how to check which action is currently running on my SKNode. I know of .hasActions() but this is returning a general true/false value, which does not help me in my situation.

Does anyone have a better solution?

Thanks in advance


Solution

  • When you start running an action, you assign a key to it using this method:

    yourNode.run(someAction, withKey: "someKey")
    

    You can then get the action with your key using:

    yourNode.action(forKey: "someKey")
    

    If the above cal returns nil, that means the node is not running the action!