Multiple scenes problem in setup

Hi there,

im using Phaser with Typescript and in only allows me to select one scene. (Without using an array in scene parameter)

If I use an array of Scenes in the scene parameter, it gives me the following error:

 TS2345: Argument of type '{ type: number; width: number; height: number; physics: { default: string; arcade: { gravity: { y: number; }; }; }; scene: (typeof GameScene)[]; }' is not assignable to parameter of type 'GameConfig'.
  Types of property 'scene' are incompatible.
    Type '(typeof GameScene)[]' is not assignable to type 'Function | Scene | SettingsConfig | Scene[] | SettingsConfig[] | CreateSceneFromObjectConfig | CreateSceneFromObjectConfig[] | undefined'.
      Type '(typeof GameScene)[]' is not assignable to type 'Scene[]'.
        Type 'typeof GameScene' is missing the following properties from type 'Scene': sys, game, anims, cache, and 22 more.

I have the following setup when having the error:

import Phaser from "phaser";
import guitar_sound from "../common_assets/sounds/395217__ueffects__guitar-tune-3-sailsmen.wav";

class GameScene extends Phaser.Scene {
  constructor() {
super("FirstScene");
  }

  init() {}

  preload(): void {
this.load.audio("guitar_sound", guitar_sound);
  }

  create(): void {
this.add.text(20, 20, "Loading game...");
// TODO
  }
  update(time: number, delta: number): void {
// TODO
  }
}

var config = {
  type: Phaser.AUTO,
  width: 800,
  height: 600,
  physics: {
    default: "arcade",
    arcade: {
      gravity: { y: 300 }
    }
  },
  scene: [GameScene]
};

export class StarfallGame extends Phaser.Game {
  constructor(config: Phaser.Types.Core.GameConfig) {
    super(config);
  }
}

window.onload = () => {
  var game = new StarfallGame(config);
};

Donā€™t know if I am doing something wrong but I look already a lot of tutorials and it seems im doing goodā€¦

Thanks in advance for the help :slight_smile:

Iā€™m also having this problem, and I didnā€™t have this in the previous version. Maybe some of the types were broken in the last update (which was just a couple days ago).

What version of phaser are you using?

try this:

var config = {
  type: Phaser.AUTO,
  width: 800,
  height: 600,
  physics: {
    default: "arcade",
    arcade: {
      gravity: { y: 300 }
    }
  },
  scene: [new GameScene()]  // <-- using actual instance of GameScene instead of its type definition, I think?
};

The type definitions were just updated in the new release a week or two ago and now the scene property on GameConfig is no longer just object, it is now Phaser.Scene | Array<Phaser.Scene> | Phaser.Types.Scenes.SettingsConfig | Phaser.Types.Scenes.SettingsConfig[] | Phaser.Types.Scenes.CreateSceneFromObjectConfig | Phaser.Types.Scenes.CreateSceneFromObjectConfig[] | Function and donā€™t ask me why but thatā€™s probably why we have to use an instance of the scene class instead of the class definition.

Someone who understands TS better than I do can hopefully enlighten us!

1 Like