这个问题可能有点太宽泛,但考虑到 Phaser 3,它仍然取决于您的菜单的用途。
我认为大多数游戏都有一个主菜单,一般会在游戏第一次启动时调用,然后就不会再次调用。
如果这是游戏内菜单,可以更改设置或可以重置/重新启动游戏的一部分,那么重定向到完全不同的场景可能没有意义。
随着 Phaser 3 对多场景的支持 - 与开发日志 #119 https://phaser.io/phaser3/devlog/119 and 开发日志#121 https://phaser.io/phaser3/devlog/121可能是当前最好的信息源 - 另一种选择是在当前场景中启动一个新场景来处理这个问题。
但是,如果这实际上只是 UI,那么没有什么可以阻止您创建叠加层,而不是生成整个场景。
如果您担心性能,我可能会考虑是否需要调用整个菜单,或者简化的菜单是否可行。另外,请确保在进入菜单和主游戏之前预加载资源。
我个人使用“启动”>“预加载器”>“启动画面”>“主菜单”>“主游戏场景”,其中预加载器加载了我需要的大部分资源。这样做的缺点是初始负载较长,但优点是此后负载最小。
场景转换
我如何处理这些我的入门模板 https://github.com/JamesSkemp/phaser-starter-templates/tree/master/v3就是在创建场景时将场景添加到场景管理器中。然后我过渡start
到第一个场景。
this.scene.add(Boot.Name, Boot);
this.scene.add(Preloader.Name, Preloader);
this.scene.add(SplashScreen.Name, SplashScreen);
this.scene.add(MainMenu.Name, MainMenu);
this.scene.start(Boot.Name);
然后我就简单地保留start
根据需要处理接下来的场景。
this.scene.start(Preloader.Name);
对于另一个使用多个场景的游戏,我最终创建了以下函数(TypeScript)来处理这个问题:
private sleepPreviousParallelScene(sceneToStart: string): Phaser.Scene {
if (this.uiSceneRunning !== sceneToStart) {
// Make sure that we properly handle the initial state, when no scene is set as running yet.
if (this.uiSceneRunning !== "") {
this.scene.get(this.uiSceneRunning).scene.sleep();
}
const newScene = this.scene.get(sceneToStart);
newScene.scene.start();
this.scene.bringToTop(sceneToStart);
this.uiSceneRunning = sceneToStart;
return newScene;
} else {
return this.scene.get(this.uiSceneRunning);
}
}
在我使用它的游戏中,我试图复制一个标准选项卡界面(就像上面的开发日志中看到的类似文件夹的界面)。