11

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.

1 Answer 1

14

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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.