Reputation: 145
I'm using the following to pause my game
self.scene?.paused = true
When the scene is paused, however, all SKAction
s stop. What can I do to allow some of the actions to continue to work?
Upvotes: 1
Views: 66
Reputation: 1664
Add certain nodes to different SKNode
so instead you can only pause the the layer (SKNode) that you wish to pause. It would look something like this:
let gameLayer = SKNode()
let pauseLayer = SKNode()
Now when you want to add a child to the scene, instead add it to a layer:
gameLayer.addChild(gameSceneNode)
pauseLayer.addChild(pauseSceneNode)
Don't forget to add the layers to the scene too
addChild(gameLayer)
addChild(pauseLayer)
To pause a layer write this:
Swift 3
gameLayer.isPaused = true
Swift 2
gameLayer.paused = true
Note that in this example, all the nodes on the gameLayer
will be paused, however everything on the pauseLayer
will not.
Upvotes: 3
Reputation: 9777
You need to design your node tree in a way where you can pause certain nodes (the gameplay nodes, for example), and not pause others (the pause menu nodes, for example). When you set the paused
property on a node, it applies to all of its children as well.
An example node hierarchy:
GameScene
GameplayNode
Character
Enemy
Enemy
PauseMenu
PlayButton
VolumeButton
If you want to animate your PlayButton
while the game is paused, you can set the GameplayNode.paused
to true
, and still have working SKAction
's for your pause menu.
Upvotes: 2