Swift, SpriteKit - Pause whole script
Asked Answered
M

1

5

Is it possible to pause the whole script in GameScene using code from the GameViewController? I do not want to delay/pause the thread. There are multiple activities and functions going on at the same time and I would like to pause everything.

I would also like to be able to resume after having paused.

For example, in the GameViewController:

GameScene.pause()

and

GameScene.resume()

Thank you in advance.

Mochun answered 25/3, 2016 at 23:24 Comment(0)
M
7

Pausing within the GameScene

Pausing the scene:

self.paused = true (self is the GameScene).

Pausing the view (SKView):

self.view?.paused = true

Pausing within the GameViewController

Pausing the scene:

let skView = self.view as! SKView
skView.scene?.paused = true

Pausing the view (SKView):

let skView = self.view as! SKView
skView.paused = true

To unpause just set paused property to false.

Molnar answered 25/3, 2016 at 23:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.