0
votes
func pause() {
    pausedSpeed = self.speed
    self.speed = 0
    backgroundMusicPlayer.pause()
    worldNode.alpha = 0.7

    resumeButton = SKShapeNode(rectOfSize: CGSize(width: 100, height: 50))
    resumeButton.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2 - 50)
    resumeButton.physicsBody = SKPhysicsBody(rectangleOfSize: CGSize(width: 100, height: 50))
    resumeButton.name = resumeButtonName

    pauseLabel = SKLabelNode(text: "PAUSED")
    pauseLabel.fontSize = 100
    pauseLabel.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2 + 100)
    pauseLabel.fontColor = UIColor.blackColor()

    worldNode.addChild(resumeButton)
    worldNode.addChild(pauseLabel)
}

Even thought I set self.speed to 0, a node still keeps moving. Any ideas why this might be happening?

1
make your SKView pause by set view.paused = true - duan
It does pauses the game. But now it doesn't add the label and the button. How do I do stuff after pausing the game? - Lalit Prabhu
The resume button works, but it doesn't show the nodes. - Lalit Prabhu
see my answer below. - duan

1 Answers

0
votes

Do not change the speed of the node. Just change node.paused = true

In your case, you should define all your control buttons on one SKNode, and declare all the game elements on another SKNode. In that case, if you want to pause the game, just make the second SKNode pause.