Minious / CodeFarm

2 stars 0 forks source link

Create SceneManager #62

Closed Minious closed 4 years ago

Minious commented 4 years ago

When a Scene tries to access an other Scene or when a game object tries to access a Scene, the Scene has to be casted to the right type because the getScene method provided by Phaser returns a generic Scene type.

Example with WorldScene : (this.scene.game.scene.getScene("WorldScene) as WorldScene).doSomething()

A SceneManager allowing access to any scene easily, could simplify these long expressions. The SceneManager would have a member variable for each Scene.

Like :

private _controllerScene: ControllerScene;
private _worldScene: WorldScene;
private _uiScene: UiScene;

get controllerScene(): ControllerScene { return this._controllerScene; }
get worldScene(): WorldScene { return this._worldScene; }
get uiScene(): UiScene { return this._uiScene; }

The SceneManager could be global or be a member of each Scene.

If member of each Scene, the access to a Scene from a game object would then be : this.scene.sceneManager.worldScene From a Scene : this.sceneManager.worldScene

Is it a good solution ? Should ask the Forum.