Update layer text created with this.add.container

Hi Guys!

I’ve created a modal that shows at the end of my game, with a score, but following the tutorial, I’ve added the modal before the game started and now I don’t know how can I update the text inside my createModal function
var text = this.add.text(centreX, centreY,'well done',{fontSize:'20px'})...
this.add.container(0,0,[text, ...])
Please help me, how my updateModal should look like? thanks.
Beatrix

:wave:

text.setText(…);

Hi, I’ve tried to find it in the layer, and override the value, but the overlay has already been drawn and it’s not updating.
this.gameOverLayer.list[2]._text = this.totalScore / 1000;

Show code for the whole scene please.

Hi, I can’t, it’s a huge application. But if you could show me an example how do you make a simple score modal and update it with the latest score, that would be a huge help.

I’ve tried this.gameOverLayer.update(), not working, this.gameOverLayer.list.update() undefined.
I could override the values in the modal, I can console.log them out, but the modal still shows the old values.

The only solution I’ve found is to find the index of the element in the list array, remove it from the array and recreate it, but that’s a huge repetition of code.

this.gameOverText = this.add.text(/*…*/);
this.gameOverLayer = this.add.container(0, 0, this.gameOverText);
// …
this.gameOverText.setText('SCORE');

Hi, tried, but every time the game ends another overlay is created, and open on top of each other, which breaks the game and I couldn’t find any way to destroy the old gameOverLayer.

If there would be a solution to destroy an element that has been added to ‘this’, that would be awesome, if there are no way to update values otherwise.

Thank you for all your effort Samme! :slight_smile:

Create the overlay once and hide it, then show it when the game is over, etc.

Or this.gameOverLayer.destroy().

hi, that’ exactly how it works. its created, then hidden, then showing at the end of the game, showing the old data, that was assigned when modal was created. Its not updating even if I update the array in this. destroy returned an error sys of undefined.