Pass data between scenes

Hello,

I have a class custom object in my GameScene.

this.player = new Player(
this,
this.game.config.width * 0.5,
this.game.config.height * 0.5,
“playerShip”
);
This object have lives and score. Which is the best way to pass all the player data into another scene?

Hi,

In scene A:

this.scene.events.emit('playerData', { data: this.player.data });

In scene B:

this.mainScene = this.scene.get("sceneA name");
this.mainScene.events.on('playerData', (data) => {
  // your code
});
1 Like