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

11
我正在使用Phaser 3制作游戏,但我似乎找不到如何从GameScene将得分传递到GameOverScene的方法。
1个回答

14
调用 this.scene.start 时,您可以向场景传递可选数据。 this.scene.start(key, data),其中包含官方演示
您可以在场景中使用 init 来检索数据。
因此,在您的 GameScene 中,您可能会有以下内容:
this.scene.start('GameOverScene', { score: this.playerScore });

然后在你的GameOverScene中应该有类似以下的内容:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接