I' ve got a text displayed in PhaserJS 3 game, then the method onEvent runs on loop adding new text to the current text, it works until it finds '\n', but it gives no error at all.
function create() {
this.savedText = this.add.text(0, 100, "Starting text display")
this.newText = "This text should be displayed \n in two lines"
this.index = 0
this.timedEvent = this.time.addEvent({ delay: 100, callback: this.onEvent, callbackScope: this, loop: true })
}
onEvent() {
let textDisplayed = ""
if(this.index < parseInt(this.newText.length)) {
textDisplayed += this.newText.charAt(this.index)
this.savedText.text += textDisplayed
this.index++
}
}
How can I fix this? Any hints? Thanks in advance.
If the code you have posten, in your question, is 100% the same as in your application, you just missed the keyword
functionbeforeonEvent(). Because your code seems to basically work:Here a working Demo: