ios - 在 Sprite Kit 中的场景之间导航?

标签 ios sprite-kit skscene

假设我从一个场景 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 编程指南

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

关于ios - 在 Sprite Kit 中的场景之间导航?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24728966/

相关文章:

ios - 我如何获取并删除 SKNode 的父节点?

ios - didBeginContact 方法不起作用

swift - SKScene 可视大小小于 View 边界

ios - 如何只允许在场景中的特定区域进行触摸?

swift - 添加到新 SKScene 时 SKEmitterNode 消失

iphone - 使用 Ad Hoc 配置文件安装 iOS 应用程序时出错

支持点击对焦的 iOS 设备

ios - 如何在浮点值中显示两位数字

ios - Xcode 自动布局不断改变我的布局

iOS SpriteKit 重叠 SKSpriteNodes/images