Show / hide sprites and texts in Phaser

I have an image and some text that I want to show / hide:

overlay = this.game.add.image( 0, 0, this.custom_texture.generateTexture() ); overlay_text = this.game.add.text( 0, 0, 'TESTING 123', style ); 

I tried the destroy() function, but I couldn’t get them back, and I don’t think it is necessary to destroy them if I just want to hide and show them.

+9
phaser-framework
source share
2 answers

This is more intuitive than I thought.
To hide:

 overlay.visible = false; overlay_text.visible = false; 

Show:

 overlay.visible = true; overlay_text.visible = true; 
+19
source share

In one insert, we can switch the hide / show.

 overlay.visible= !overlay.visible; overlay_text.visible = !overlay_text.visible; 
+1
source share

All Articles