Alec O'Connor
Alec O'Connor

Reputation: 265

Swift: Presenting a Scene over another Scene

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.

Upvotes: 1

Views: 1754

Answers (1)

Knight0fDragon
Knight0fDragon

Reputation: 16827

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.

Upvotes: 4

Related Questions