I am initializing phaser 3 game component using angular 7. Below is the html code I am using -
<phaser-component [gameConfig]="alphacrossGameConfig" (gameReady)="onGameReady($event)"></phaser-component>
And, the ts file has the following code -
public readonly alphacrossGameConfig = {
type: Phaser.AUTO,
scale: {
mode: Phaser.Scale.FIT,
width: window.innerWidth * window.devicePixelRatio,
height: window.innerHeight * window.devicePixelRatio,
parent: 'alphaCross'
},
physics: {
default: 'arcade',
},
backgroundColor: '#000000',
banner: true
}
public onGameReady(game: Phaser.Game): void {
console.log("inside on game ready ", game)
console.log("this.alphacrossBackground ", this.alphacrossBackground)
game.scene.add('Scene', this.alphacrossBackground, true)
this.alphacrossBackground.alphacrossGameComp = this;
}
On first time, phaser game is initializing correctly and I am entering the game scene. But once I leave the game room and trying to re-enter the room( or re-initializing phaser game component), I am getting the following error -
"ERROR TypeError: Cannot set property 'game' of null
at PluginManager.addToScene (phaser.js:69109)
at Systems.init (phaser.js:33612)
at SceneManager.createSceneFromInstance (phaser.js:72938)
at SceneManager.add (phaser.js:72583)
at AlphacrossGameComponent.push../src/app/component/alphacross-game/alphacross-game.component.ts.AlphacrossGameComponent.onGameReady (alphacross-game.component.ts:36)
at Object.eval [as handleEvent] (AlphacrossGameComponent.html:1)
at handleEvent (core.js:23107)
at callWithDebugContext (core.js:24177)
at Object.debugHandleEvent [as handleEvent] (core.js:23904)
at dispatchEvent"
And the following error as well -
ERROR CONTEXT
on html code
I am using the following code to leave the game lobby -
this.game.destroy(true,true);
this.sys.game.destroy(true);
Any help is really appreciated. Thanks!