Phaser 3 Arcade 物理系统未激活

Phaser 3 Arcade physics not getting activated

我正在使用 Phaser 3(3.24),以下是我初始化游戏的配置

GAME_CONFIG: {
    type: Phaser.AUTO,
    backgroundColor: '#fff',
    scale: {
      width: 1200,
      height: 470,
      mode: Phaser.Scale.ScaleModes.NONE,
    },
    parent: 'marathon-game',
    physics: {
      default: 'arcade',
      fps: 60,
      arcade: {
        gravity: { y: 300 },
        debug: true,
      },
    },
  }

当我开始我的第一个场景并检查 this.scene.physics 它 returns 未定义...知道为什么会发生这种情况或我可能做错了什么。

我认为这是因为配置中缺少您的场景对象。所以如果你的场景不是 class 使用:

GAME_CONFIG: {
    ...the_rest_of_your_config
    scene: {
        preload: preload,
        create: create,
        update: update
    }
   }

或者:

GAME_CONFIG: {
    ...the_rest_of_your_config
    scene: name_of_your_scene_class_goes_here
   }