Asaf
Asaf

Reputation: 8216

Show/Hide Sprites & 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 wasn't able to bring them back, plus I don't think it's necessary to destroy them if I simply want to hide & show them.

Upvotes: 14

Views: 18083

Answers (2)

Prashant
Prashant

Reputation: 286

In one Liner, we can toggle hide/show.

overlay.visible= !overlay.visible;
overlay_text.visible = !overlay_text.visible;

Upvotes: 3

Asaf
Asaf

Reputation: 8216

It's more intuitive than I thought it would be.
To hide:

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

To Show:

overlay.visible = true;
overlay_text.visible = true;

Upvotes: 31

Related Questions