I must be missing something in the docs, but it’s not clear to me how to create globally available properties for a Phaser game. I’m working in Typescript.
My goal is to have a helper class that I instantiate only once, and then is available in all scenes.
I came up with the following, perhaps someone can shed some light on this? Is this the correct way to go about it?
export class SuperCoolGame extends Phaser.Game {
public arcade:Arcade
constructor(config: GameConfig) {
super(config)
this.arcade = new Arcade()
}
}
}
And then from a Scene:
export class GameOver extends Phaser.Scene {
constructor() {
super({key: "GameOver"})
}
create(): void {
let supercoolgame = this.game as SuperCoolGame
supercoolgame.arcade.someFunction()
}
}