SpriteKit SKAction pause lag
I have an action and I used NSTimer
to create it, but I changed it to SKAction so that it stops when the scene is stopped:
let SpawnAction = SKAction.sequence([SKAction.waitForDuration(0.5), SKAction.runBlock(Spawn)])
self.runAction(SKAction.repeatActionForever(SpawnAction))
Now the problem is with a delay that exists in a piece of waitForDuration
code that I think it won't work right after the scene is paused.
This is the code I am using to pause / pause the game:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
for touch in (touches as! Set<UITouch>) {
let location = touch.locationInNode(self)
let node = self.nodeAtPoint(location)
if (node.name == "Pause") {
PauseLabel.removeFromParent()
self.addChild(ResumeLabel)
self.runAction(SKAction.runBlock(self.pauseGame))
}
else if (node.name == "Resume") {
self.view!.paused = false
self.addChild(PauseLabel)
ResumeLabel.removeFromParent()
}
else {
//Other code...
}
}
}
func pauseGame() {
self.view!.paused = true
}
I would like someone to tell me how to properly force / pause the SpriteKit game as all the methods I got from the internet didn't work right for me. Thank.
source to share
I'm not sure if this will work for you. but under the function didMoveToView
inside the selected handler for the button I use to pause:
i used self.gameState = .Pause
and also useself.physicsWorld.speed = 0
both stop the game play, and the physical world helps stop any action that might be taking place on your sprites.
hope this helps you.
source to share