将场景添加到 Phaser 3 游戏不起作用

Adding scenes to Phaser 3 game not working

所以我尝试将场景添加到我的 Phaser 3 game.js 文件中(您可以查看代码 here and which you can see in (very much beta) action here),

根据

let gameScene = new Phaser.Scene('Game');

gameScene.preload = function() {

方法描述 here 并通过

启动它们
var game = new Phaser.Game(800,800, Phaser.AUTO, 'game-div', {Game});

这只会导致黑屏。

基本上,我想通过场景创建一个开始菜单和一个游戏结束菜单。非常感谢使用上述方法添加场景或创建简单菜单的任何轻量级替代方法!

config.scene中,使用对象数组作为场景。

var scene1 = {
    key:'scene1_start_screen', preload: function(){},   create: function(){
  //start sceen create, call next scene with
  phaser_game.scene.start('scene2_game_screen');
  //stop this scene with 
  phaser_game.scene.stop('scene1_start_screen');

  },
}
var scene2 = {
    key:'scene2_game_screen',preload: function(){}, create: function(){},
}

var config = {
    type: Phaser.AUTO,
    width: 600,
    height: 600,
    backgroundColor: "#b9eaff",
    physics: {
        default: 'arcade',
        arcade: {
            gravity: { y: 200 }
        }
    },
    parent: 'game',
    scene: [scene1,scene2]

};

问题是您在此处混用了 Phaser 2 和 Phaser 3 代码。场景只是 Phaser 3 的一个功能,但是你上面的代码和你链接的文件中的代码都是 Phaser 2 代码。所以你需要坚持一个版本或另一个版本,恐怕不能像这样混搭。