我正在使用Phaser 3框架创建游戏。我的游戏使用的是滚动相机,因此根据我搜索的内容,显示分数的最简单方法是使用容器。我试图使用补间来确保它跟随播放器,但是我似乎无法找出正确的属性。
我希望分数从玩家的正上方开始,并随其移动而移动。
如果有比使用容器更好的方法,请随时进行更改。
//Camera to follow the skater
this.cameras.main.setBounds(0, 0, 3000, gameHeight);
this.cameras.main.startFollow(skater);
// ...some code in between...
//Scoreboard
scoreBoard = this.add.container(skater.x, 50);
scoreText = this.add.text(skater.x, 50, "SCORE: 0", {fontSize: '56px', color: '#fff'});
scoreBoard.add(scoreText);
this.tweens.add({
targets: scoreBoard,
x: scoreBoard.x + skater.x,
ease: 'Linear',
duration: 1,
delay: 1,
yoyo: false,
repeat: -1
});
注意:所有这些代码仅在
create()
函数中。 最佳答案
解决方案非常简单。在update()
函数中,将scoreText
变量设置为skater.body.position.x
,如下所示:
function update() {
scoreText.x = skater.body.position.x;
}
关于javascript - 如何使我的文字跟随Phaser 3中的播放器?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58585425/