Moving between scenes in a Sprite Kit?

Let's say I start with the initialScene scene. This scene contains several buttons. When the user clicks button A in this scene, I represent sceneA . So my code will look like this:

 sceneA* scene = [[sceneA alloc] init]; [self.scene.view presentScene: scene]; 

My first question is: when a sceneA instance sceneA presented from initialScene , does it fit on top of the initialScene instance or replace it? Does the initialScene instance initialScene into memory when a new scene appears?

I ask about this because sceneA will have a back button which, when clicked, returns the user to the original scene. Can I just create a new instance of initialScene inside sceneA and present it, or will this lead to multiple instances of the same scenes stacked on top of each other? Basically, can I just do this in sceneA ?:

 if(...) { //if user taps back button initialScene* iniScene = [[initialScene alloc] init]; [self.scene.view presentScene: iniScene]; } 

Or is there a better way to do this? Please let me know if I can explain this further.

+6
source share
1 answer

Sprite Kit simplifies the transition between scenes. You can also constantly keep scenes around you or get rid of them when you transition between them. In this example, you create a second scene to explore some other game behavior. When "Hello world!" the text disappears from the screen, the code creates a new scene and proceeds to it. Hello scene will exit after the transition.

Sprite Kit Programming Guide

https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/GettingStarted/GettingStarted.html#//apple_ref/doc/uid/TP40013043-CH2-SW10

+5
source

Source: https://habr.com/ru/post/972155/


All Articles