如何在 Phaser 3 中将数据从一个场景传递到另一个场景?

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

我正在 Phaser 3 中制作游戏,但我似乎找不到如何将分数从 GameScene 传递到 GameOverScene。

调用时this.scene.start可以向场景传递可选数据

this.scene.start(key, data), which has an official demo.

您可以在场景中使用init来检索数据。

因此在您的 GameScene 中您可能有如下内容:

this.scene.start('GameOverScene', { score: this.playerScore });

然后在你的 GameOverScene 中你应该有如下内容:

init: function (data)
{
    console.log('init', data);
    this.finalScore = data.score;
}