Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass data from scene to scene in phaser 3?

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.

like image 602
Kacim Fedjkhi Avatar asked Nov 17 '18 22:11

Kacim Fedjkhi


1 Answers

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;
}
like image 99
James Skemp Avatar answered Jan 01 '23 19:01

James Skemp