首页 > 解决方案 > 向 Phaser 3 游戏添加场景不起作用

问题描述

因此,我尝试将场景添加到我的 Phaser 3 game.js 文件中(您可以在此处查看代码,也可以在此处查看(非常多的测试版)操作),

根据

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

gameScene.preload = function() {

此处描述的方法并通过以下方式启动它们

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

这只导致黑屏。

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

标签: javascriptphaser-framework

解决方案


在 中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]

};

推荐阅读