I am currently making a flappy bird clone, and have a SKAction (runActionForever) in my didMoveTOView method. However, once I die, I want to terminate that action, by which is followed a popup screen.
override func didMoveToView(view: SKView) {
var endlessAction = SKAction.runActionForever(spawn, delay)
}
func died() {
endlessAction..... ?
screenDied.position = CGPoint(self.frame.x / 2, self.frame.y / 2)
addChild(screenDied)
}
Now, in another function, died(), how do I end this action? - so I can then make a screen popup.
Thanks!
SKAction Class Reference : https://developer.apple.com/documentation/spritekit/skaction
SKNode Class Reference : https://developer.apple.com/documentation/spritekit/sknode#//apple_ref/occ/instm/SKNode/runAction:withKey:
Adding Actions to Nodes : https://developer.apple.com/library/archive/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/AddingActionstoSprites/AddingActionstoSprites.html
To cancel actions that a node is running, call its removeAllActions method. All actions are removed from the node immediately. If a removed action had a duration, any changes it already made to the node remain intact, but further changes are not executed.
Normally, you can’t see which actions a node is executing and if you want to remove actions, you must remove all of them. If you need to see whether a particular action is executing or remove a specific action, you must use named actions. A named action uses a unique key name to identify the action. You can start, remove, find, and replace named actions on a node.
If you need to remove all actions from your node, you can use the removeAllActions method. However, if you need to remove a specific action you need to run it with the method named runAction:withKey:.
If an action with the same key is already running, it is removed before the new one is added.
Also, you can use actionForKey: to see if an action is running on a specific node.
Then use removeActionForKey: to remove the action.
PS : If you're looking to pause the actions and the node itself, you might want to look for the paused property on your node.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With