I'm trying to toggle between 'Pause' and 'Resume' text when pausing and resuming, i tried the following in create
:
gameState.playPauseText = this.add.text(660, 547, 'Pause', { fontFamily: 'Roboto Mono, monospace', fontSize: '20px', fill: '#FFFFFF' });
then tried changing that inside a callback function:
gameState.playPauseArea.on('pointerdown', () => {
if(!gameState.isPaused) {
gameState.playPauseText.setText('Resume');
game.loop.sleep();
gameState.isPaused = true;
}
else {
gameState.playPauseText.setText('Pause');
game.loop.wake();
gameState.isPaused = false;
}
});
then i tried same, but changed .setText
to .text =
. The best i got from all above is to change text to 'Resume' after 2 clicks, but never back to 'Pause'.
I also tried the following in update
:
if(gameState.isPaused) {
gameState.pauseText.setText('Resume')
} else {
gameState.pauseText.setText('Pause');
}
that didn't do anything.
I also tried creating two separate texts and hiding one with setVisible(false)
and tried all of the above toggling both 'Resume' and 'Pause' between setVisible(true)
and setVisible(false)
.
also nothing.
I use .setText()
somewhere in my code, to change score text and it works fine.