0
votes

Right now I've got it where if I click on the pause button I've made, it goes to my pause menu. When I go back to the game screen via the button I made to do that, the game has reset itself to the beginning.

I've got a "go back to the game button" and a reset the game button.

How do I get those two to act correctly?

I don't even really know where to begin with this because I don't know if the game is clearing when I'm initially leaving the screen or when I'm going back to it. I thought I had read the default behavior was to save the state of a screen when you navigated off of it.

1
I believe Apple Docs state that if you keep a reference to your scene, it will persist. - Epic Byte

1 Answers

1
votes

When you change your game view controller (gameVC) to your menu view controller (menuVC), if there isn't any reference remaining everything gets deallocated. Therefore, when you go back to your gameVC you're allocating new objects (scene, nodes, ...).

What you might be looking for, to pause your game, is the paused property.

On your SKScene (which is a SKNode) : https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKNode_Ref/index.html#//apple_ref/occ/instp/SKNode/paused

paused

A Boolean value that determines whether actions on the node and its descendants are processed.

If the value is YES, the node (and all of its descendants) are skipped when a scene processes actions.

On you SKView : https://developer.apple.com/library/prerelease/mac/documentation/SpriteKit/Reference/SKView/index.html#//apple_ref/occ/instp/SKView/paused

paused

A Boolean value that indicates whether the view’s scene animations are paused.

If the value is YES, the scene’s content is fixed onscreen. No actions are executed and no physics simulation is performed.

The update: method won't be called if the SKView is paused.