假设我从一个场景 initialScene
开始。这个场景包含几个按钮。当用户点击这个场景中的按钮 A 时,我将呈现 sceneA
。所以我的代码看起来像这样:
sceneA* scene = [[sceneA alloc] init];
[self.scene.view presentScene: scene];
我的第一个问题是,当 initialScene
中出现 sceneA
实例时,它是堆叠在 initialScene
实例之上还是它取代了吗?当呈现新场景时,initialScene
的实例是否在内存中被释放?
我问这个是因为 sceneA
将有一个后退按钮,当点击该按钮时,用户将返回到初始场景。我能否在 sceneA
中创建一个新的 initialScene
实例并呈现它,或者这会导致相同场景的多个实例堆叠在一起吗?基本上,我可以只在 sceneA
中执行此操作吗?
if(...) { //if user taps back button
initialScene* iniScene = [[initialScene alloc] init];
[self.scene.view presentScene: iniScene];
}
或者有更好的方法吗?如果有任何方法可以进一步澄清这一点,请告诉我。
最佳答案
Sprite Kit makes it easy to transition between scenes. You can either keep scenes around persistently, or dispose of them when you transition between them. In this example, you create a second scene class to learn some other game behaviors. When the “Hello, World!” text disappears from the screen, the code creates a new scene and transitions to it. The Hello scene is discarded after the transition.
Sprite Kit 编程指南
关于ios - 在 Sprite Kit 中的场景之间导航?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24728966/