Reputation: 143
I'm making a game in Phaser 3 but I can't seem to find how to pass the score from a GameScene to a GameOverScene.
Upvotes: 13
Views: 10363
Reputation: 8571
When calling this.scene.start
you can pass optional data to the scene.
this.scene.start(key, data)
, which has an official demo.
You can use the init
in a scene to retrieve the data.
So in your GameScene
you might have something like the following:
this.scene.start('GameOverScene', { score: this.playerScore });
Then in your GameOverScene
you should have something like the following:
init: function (data)
{
console.log('init', data);
this.finalScore = data.score;
}
Upvotes: 16