Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 461
mahclark Avatar asked Mar 12 '23 19:03

mahclark


1 Answers

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.

like image 193
Whirlwind Avatar answered Mar 29 '23 09:03

Whirlwind