Reputation: 713
I have an SKAction that is triggered running withKey:"running". I also have other actions with keys. In my case I would find it handy, if I could check if eg SKAction with the key "running" is currently running or not.
Something like:
if (mySpriteNode.runsAction("running")) {
// do some magic code
}
For now I just found that I can look if there are actions in general applied to a node, like
mySpriteNode.hasActions
Does someone have an idea?
Upvotes: 3
Views: 893
Reputation: 21
if myspritenode.action(forkey: "some key") != nil {
//runs if action is active
}
This solution worked for me.
Upvotes: 1
Reputation: 270980
I found this method. It might be what you need:
func action(forKey key: String) -> SKAction?
If an action exists that matches the key, the action object is returned. Otherwise, nil is returned.
You can use it like so:
if let _ = mySpriteNode.action(forKey: "someKey") {
// action is running
} else {
// action is not running
}
Upvotes: 8