Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 607
Asaf Avatar asked Mar 19 '15 15:03

Asaf


People also ask

What is the command used to show the hidden sprite?

In case you want to show one sprite on key press "a" and hide the other sprite and do the opposite in case of key press "b" then this is pretty simple. Here below you see the script for the sprite that must be shown on "b" keypress.

What is the use of hide block?

The Hide Block control allows you to completely hide any block in WordPress from public view. It was one of the first controls included in Block Visibility, all the way back in version 1.0.


2 Answers

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;
like image 130
Asaf Avatar answered Oct 17 '22 16:10

Asaf


In one Liner, we can toggle hide/show.

overlay.visible= !overlay.visible;
overlay_text.visible = !overlay_text.visible;
like image 29
Prashant Avatar answered Oct 17 '22 15:10

Prashant