I’m very new to Phaser, and I’m Japanese, So this topic may be confusing.
I’m making Typing Game. I’d like to change color of Text_Typed
to blue, but it is displayed as <font color='blue'>Gam</font>e
.
Is there any way to display as “Game”(Gam is blue and e is black)?
const words = ["Hello", "typing", "Game"];
let currentWord = words[Math.floor(Math.random() * words.length)];
let currentIndex = 0;
const text = this.add.text(400, 300, currentWord, { font: "bold 48px Arial", fill: "#000" });
text.setOrigin(0.5);
this.input.keyboard.on('keydown', function (event) {
if (event.keyCode >= 65 && event.keyCode <= 90) {
const char = event.key.toLowerCase();
if (char === currentWord[currentIndex].toLowerCase()) {
const Text_Typed = currentWord.substring(0, currentIndex + 1).fontcolor('blue')
const Text_Untyped = currentWord.substring(currentIndex + 1);
text.setText(Text_Typed + Text_Untyped);
currentIndex++;
if (currentIndex === currentWord.length) {
currentIndex = 0;
currentWord = words[Math.floor(Math.random() * words.length)];
text.setText(currentWord);
}
}
}
});
}