Suspend SKAction in Spritekit with Swift

I have the following code to move SKSpriteNode .

 let moveDown = SKAction.moveBy(CGVectorMake(0, -120), duration: 1) let moveUp = SKAction.moveBy(CGVectorMake(0, +120), duration: 1) let moveSequence = SKAction.sequence([moveDown, moveUp]) square.runAction(SKAction.repeatActionForever(moveSequence)) 

This moves SKSpriteNode up and down forever. Is there any way I could pause this SKAction ? So will SKSpriteNode freeze in its current position, and then, when I decide, continue moving?

I only want to pause the movement of this SKSpriteNode . I do not want to pause SKScene . Just the movement of this 1 SKSpriteNode

+8
source share
3 answers

You must start the action with the key:

  square.runAction(SKAction.repeatActionForever(moveSequence), withKey:"moving") 

Then use the action speed property to pause it:

 if let action = square.actionForKey("moving") { action.speed = 0 } 

or to disable it:

 action.speed = 1 
+11
source

Alternative to @Whirlwind's answer, if you have a bunch of actions that need to be paused that are not part of a group, and not just a movement, you just need to pause the node itself. All SKNodes have the paused property associated with it.

Ex. square.paused = true

+8
source

SCNNode.paused has been renamed SNCNode.isPaused.
You should be able to pause the following animation: square.isPause = true Restart the animation: square.isPaused = false

0
source

All Articles