Hi everyone! I want to make a textbox that appears when certain conditions are met. When the condition is met, the textbox appears in a little animation and once the animation is over, it displays the text. Normally, this should work okay, but I have a problem when trying to display text based on an array. The first iteration works just fine, but after the first call “not with the battery” the game iterates through the command twice. For example, the first time, the game would display the text in array[0] like it should, but the next time it displays the text found in array[2], and the next time it’s called it will display the text in array[5]. Anyone know what the problem is? This doesn’t happen if I don’t play an animation.
Here’s the code in case if anyone needs to look at it. I apologize for the spaghetti code beforehand.
makeText(type){
this.textBox.text = “”;
this.mainText.text = “”;
this.textAnimation.setAlpha(1);
this.textAnimation.anims.play(‘textAnim’, true);
this.textAnimation.on(“animationcomplete”, () => {
this.textAnimationComplete = true;
if(type === “battery”){
this.textBox.text = “Battery Obtained!”;
this.mainText.text = “Your maximum battery has increased by 25!”;
}
else{
this.textBox.text = this.words.shift();
console.log(this.words);
this.mainText.text = “”;
}
});
}