Hi everyone, I’m having an issue with my interaction system in my tutorial level. The issue is that I have a dialogue box with dialogue text that keeps on stacking on continuously once I change the value of my three variables this.checkA = false
, this.checkD = false
, and this.checkSPACE = false
When my level loads, I display a dialogue box to the player from one of the NPCs. This one only shows up when the above variables have a boolean of false
The only way I know to check for keypresses is within the update function, and keypresses are what I’m using to trigger my variables above to change from false
to true
When they are true
I change the text in my dialogue and destroy the previous text. But I can’t figure out how to stop the update()
function from basically breaking everything. I know update()
runs continuously so basically I need a way to break out of a portion of the loop.
create() {
this.checkA = false;
this.checkD = false;
this.checkSPACE = false;
if (this.checkA === false && this.checkD === false) {
this.dialWindow = this.dialogue.create(960, 500, "dialInstructor").setScale(1.25); // create the dialogue box
this.dialogueText1 = this.add.text(this.dialWindow.x - 260, this.dialWindow.y - 280, this.interact.dialObj.dialInstructor.dialIntro1, {fontFamily: "sans-serif", fontSize: 30, lineSpacing: 2, fontColor: 0xffffff});
}
}
update() {
if (this.checkA === true && this.checkD === true) {
this.dialogueText1.destroy();
this.dialogueText2 = this.add.text(this.dialWindow.x - 260, this.dialWindow.y - 280, this.interact.dialObj.dialInstructor.dialIntro2, {fontFamily: "sans-serif", fontSize: 30, lineSpacing: 2, fontColor: 0xffffff});
}
if (this.checkSPACE === true) {
this.dialogueText2.destroy();
this.dialogueText3 = this.add.text(this.dialWindow.x - 260, this.dialWindow.y - 280, this.interact.dialObj.dialInstructor.dialIntro3, {fontFamily: "sans-serif", fontSize: 30, lineSpacing: 2, fontColor: 0xffffff});
}
if (this.cursors.left.isDown && this.checkA < 2) {
this.checkA = true;
console.log("A checked");
} else if (this.cursors.right.isDown && this.checkD < 2) {
this.checkD = true;
console.log("D checked");
} else if (this.cursors.jump.isDown && this.checkSPACE < 2) {
this.checkSPACE = true;
}
}