mahclark
mahclark

Reputation: 305

Swift, SpriteKit - Pause whole script

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.

Upvotes: 5

Views: 1115

Answers (1)

Whirlwind
Whirlwind

Reputation: 13665

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.

Upvotes: 7

Related Questions