1

I'm having trouble finding this answer. If I have a settings scene that I want to slide down over another scene, how do I do this without removing the original scene. I want to be able to transition the settings scene overtop of the game and when they click "Back" have the settings scene scroll back up and disappear.

Alec O'Connor
  • 215
  • 1
  • 3
  • 9
  • How do I differentiate whether or not I want to get rid of the previous scene? I can imagine wanting to get rid of the last scene so it doesn't clog the memory. – Alec O'Connor Feb 03 '16 at 21:52
  • Just use a "present modally, over full screen, cover vertical" segue – Paulw11 Feb 03 '16 at 22:25
  • If those three are used to display without deallocating the last view, which would I use if I wanted to deallocate it? For example, switching over to a new view of a game to start over when the player loses. – Alec O'Connor Feb 04 '16 at 14:15
  • You would typically step back to the scene before the game scene and then go back to a new game scene. You normally have a kind of "stack" of view controllers with new ones coming in top,of the old ones, the old,ones are still,in memory on the stack. For a game you can also just keep the scene and reset the game state – Paulw11 Feb 04 '16 at 18:08
  • Not sure why you are confusing the guy here, we are talking about scenes, not view controllers – Knight0fDragon Feb 05 '16 at 13:00
  • I was actually looking to use a new scene, but found the best way was to add a scene to the storyboard and use a segue to show the settings screen. The option of using SKNodes is a good answer, but not exactly what I was looking for. Nonetheless, thank you KnightOfDragon! – Alec O'Connor Feb 05 '16 at 14:35
  • just to let you know, doing it that way, you may see performance drop a lot if you have a lot going on. – Knight0fDragon Feb 05 '16 at 17:20

1 Answers1

2

Not sure why everyone is talking about view controllers here, but the easiest way to achieve what you want to do does not involve multiple scenes.

In SpriteKit, you can only have 1 scene at a time going.

So what you do, is you have an SKNode that will be used for your settings scene, and an SKNode for your main content.

Place all of your settings nodes into this setting SKNode as you would for the scene.

Place all of your main content into the main SKNode.

Add the main node to your scene for normal game functionality.

Give a high z position to the settings node so that it is on top.

Then when you need to present the settings node, you set its position to the screen height + 1/2 the SKNodes height (unless you change the anchor point).

Pause the main node if needed.

Use an SKAction on the settings node to have it move down to the spot on the screen you need it to go. (SKAction.moveToX(x:y:) should work for you).

Then when you need to leave, just call the reverse of the SKAction and unpause the main node.

Knight0fDragon
  • 15,949
  • 2
  • 20
  • 41