【发布时间】:2023-02-02 03:23:30
【问题描述】:
我正在尝试为我正在开发的平台游戏中的角色制作文本。这是我的代码:
创建方法中的代码:
this.dialog = this.add.text(880, 810, ' ', { font: '30px Futura', fill: '#FFFFFF' }).setOrigin(0.5);
更新方法中的代码:
if ((this.checkCollision(this.p1, this.goodLamb) || this.checkCollision(this.p1, this.stiches)) && (this.has("spool") && this.has("needleOne") && this.has("needleTwo")) && this.keyT.isDown) {
console.log("spool: " + this.has("spool") + " needleOne: " + this.has("needleOne") + " needleTwo: " + this.has("needleTwo"));
this.dialog.setText('Oh, thanks Peef! Now we can fix Stiches!');
}
else if ((this.checkCollision(this.p1, this.goodLamb) || this.checkCollision(this.p1, this.stiches)) && (!(this.has("spool")) || !(this.has("needleOne")) || !(this.has("needleTwo"))) && this.keyT.isDown){
console.log("spool: " + this.has("spool") + " needleOne: " + this.has("needleOne") + " needleTwo: " + this.has("needleTwo"));
this.dialog.setText('Peef! Stiches ripped herself again! Can you get the sewing supplies?');
}
else{
this.dialog.setText('');
}
请注意,this.p1 是玩家,this.goodlamb 和 this.stiches 是角色,字符串 spool、needleOne 和 needleTwo 代表物品栏中的物品。
该代码目前仅在玩家与 npc 发生碰撞并按住 T 按钮时显示文本,我通常将其用于交互。但是按住 T 按钮查看文本并不是我想要的。
我想要的结果会像这样:玩家与 npc 发生碰撞并按下按钮一次。显示一行文本。阅读该行后,玩家再次按下按钮,当前行消失,同时出现另一行文本。如此重复,直到没有更多的行。
我不确定如何解决这个问题。有什么建议么?
如果有帮助,我在 VSCode 中使用 Phaser 3,采用街机物理。
【问题讨论】:
标签: javascript text phaser-framework