# How to remove text

**URL:** <https://phaser.discourse.group/t/how-to-remove-text/742>\
**Category:** Phaser 3\
**Created:** [January 14, 2019, 4:17am UTC](https://phaser.discourse.group/t/how-to-remove-text/742 "2019-01-14T04:17:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manuel-Suarez-Abasca](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/manuel-suarez-abasca/32/412_2.png) [@Manuel-Suarez-Abasca](https://phaser.discourse.group/u/Manuel-Suarez-Abasca)\
**Post date:** [January 14, 2019, 4:17am UTC](https://phaser.discourse.group/t/how-to-remove-text/742/1 "2019-01-14T04:17:30Z")

</div>

Hello,

I have created a condition to pause the game by hitting the spacebar & resume the game when hitting the shift key.

When the game is paused, a message saying “Game Paused is added”. However, I dont find a way to remove it when game is resumed.

This is my code:

```
    function update ()
    {
      // Pause game by pressing spacebar & resume by pressing shift
      if(cursors.space.isDown){
        this.physics.pause();
        pauseGameText = this.add.text(200, 200, 'Game Paused', { font: "bold 40px Aria", fill: "#fff"});
      } else if (cursors.shift.isDown){
        this.physics.resume();
        pauseGameText.destroy();
      }

```

Any help will be appreciate it! Thanks in advance!

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [January 14, 2019, 4:22am UTC](https://phaser.discourse.group/t/how-to-remove-text/742/2 "2019-01-14T04:22:02Z")

</div>

Create the text once, in create(), the toggle it with `.setVisible(true)` or `.setVisible(false)`.

---

<div class="post-metadata">

**Author:** ![hcakar](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/hcakar/32/459_2.png) [@hcakar](https://phaser.discourse.group/u/hcakar)\
**Post date:** [January 14, 2019, 6:40am UTC](https://phaser.discourse.group/t/how-to-remove-text/742/3 "2019-01-14T06:40:40Z")

</div>

from @samme’s explanation,

```
function create() {
    pauseGameText = this.add.text(
        100, 200, 'Game Paused', 
        { fontFamily: 'Arial', fontSize: 64, color: '#00ff00' }
    )
    .setVisible(false);
}

function update() {
    if(cursors.space.isDown){
        //... Your pause code
        pauseGameText.setVisible(true);
    }
    else if (cursors.shift.isDown){
        //... Your pause code
        pauseGameText.setVisible(false);
    }

}
```

---

<div class="post-metadata">

**Author:** ![Manuel-Suarez-Abasca](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/manuel-suarez-abasca/32/412_2.png) [@Manuel-Suarez-Abasca](https://phaser.discourse.group/u/Manuel-Suarez-Abasca)\
**Post date:** [January 14, 2019, 1:28pm UTC](https://phaser.discourse.group/t/how-to-remove-text/742/4 "2019-01-14T13:28:13Z")

</div>

Thanks, I am able to add it but it doesn’t remove once is displayed in the game. Any thoughts?

---

<div class="post-metadata">

**Author:** ![hcakar](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/hcakar/32/459_2.png) [@hcakar](https://phaser.discourse.group/u/hcakar)\
**Post date:** [January 14, 2019, 1:34pm UTC](https://phaser.discourse.group/t/how-to-remove-text/742/5 "2019-01-14T13:34:26Z")

</div>

Maybe you can just use an else statment to make it invisible ? like this:

```
function update() {
    if(cursors.space.isDown){
        //... Your pause code
        pauseGameText.setVisible(true);
    }
    else {
        //... Your pause code
        pauseGameText.setVisible(false);
    }
}

```

Possibly when u press space it’s adding it maybe more then 100 time and that’s why u never saw it’s removing.  
As far as i think it should be work fine when u do it like @samme said.

---

<div class="post-metadata">

**Author:** ![Manuel-Suarez-Abasca](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/manuel-suarez-abasca/32/412_2.png) [@Manuel-Suarez-Abasca](https://phaser.discourse.group/u/Manuel-Suarez-Abasca)\
**Post date:** [January 14, 2019, 11:50pm UTC](https://phaser.discourse.group/t/how-to-remove-text/742/6 "2019-01-14T23:50:36Z")

</div>

```
function create ()
{
  pauseGameText = this.add.text(200, 200, 'Game Paused',{ fontFamily: 'Arial', fontSize: 64, color: '#00ff00'}).setVisible(false);
}

function update ()
{
  // Pause game by pressing spacebar & resume by pressing shift
  if(cursors.space.isDown){
    this.physics.pause();
    pauseGameText.setVisible(true);
  } else if (cursors.shift.isDown){
    this.physics.resume();
    pauseGameText.setVisible(false);
  }
}

```

I tried this example like you guys advised me but I don’t get the desire effect so far. I am able to add the text but it doesn’t away after. I could try do this with a button instead but I would like to be a text if possible.

---

<div class="post-metadata">

**Author:** ![hcakar](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/hcakar/32/459_2.png) [@hcakar](https://phaser.discourse.group/u/hcakar)\
**Post date:** [January 15, 2019, 9:58am UTC](https://phaser.discourse.group/t/how-to-remove-text/742/7 "2019-01-15T09:58:50Z")

</div>

Hello again @Manuel-Suarez-Abasca  
I couldn’t understand what is the problem actually, like i tried this code with out pausing anything and seting false and true toggle’s the visibility.

Can you create a fiddle maybe to show us what’s not working ? 🙂

---

<div class="post-metadata">

**Author:** ![jamespierce](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jamespierce/32/66_2.png) [@jamespierce](https://phaser.discourse.group/u/jamespierce)\
**Post date:** [January 15, 2019, 11:56am UTC](https://phaser.discourse.group/t/how-to-remove-text/742/8 "2019-01-15T11:56:32Z")

</div>

I woudn’t suggest listening to this input in your update loop. It means you will pause or un-pause the game in EVERY frame!

I assume what you want is to just pause the game 1x and then stay in pause mode until you un-pause the game again. In other words, you want to listen to the “Pause-Input” 1x and not in every frame 60 times per second.

So I think listening to the ‘keyup’ event on the keyboard could solve your problem:

```
function create ()
{
    let pauseGameText = this.add.text(200, 200, 'Game Paused',{ fontFamily: 'Arial', fontSize: 64, color: '#00ff00'}).setVisible(false);

	function handleKeyUp (e)
	{
		switch (e.code)
		{
			case 'Space':
				this.physics.pause();
				pauseGameText.setVisible(true);
				break;
			case 'ShiftLeft':
			case 'ShiftRight':
				this.physics.resume();
				pauseGameText.setVisible(false);
				break;
		}
	}
	
	this.input.keyboard.on('keyup', handleKeyUp, this);
}
```

---

<div class="post-metadata">

**Author:** ![Manuel-Suarez-Abasca](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/manuel-suarez-abasca/32/412_2.png) [@Manuel-Suarez-Abasca](https://phaser.discourse.group/u/Manuel-Suarez-Abasca)\
**Post date:** [January 16, 2019, 2:42am UTC](https://phaser.discourse.group/t/how-to-remove-text/742/9 "2019-01-16T02:42:04Z")

</div>

Hello @hcakar , @jamespierce , @samme

I just figure it out. I was just missing setting the text to `pauseGameText.setDepth(1);`

So finally my code ended like this:

function create ()  
{  
// Set text to pause game & hide it  
pauseGameText = this.add.text(200, 200, ‘Game Paused’,{ fontFamily: ‘Arial’, fontSize: 64, color: ‘#fff’}).setVisible(false);

// Set the depth to 1  
pauseGameText.setDepth(1);  
}

function update ()  
{  
// Pause game by pressing spacebar & resume by pressing shift  
if(cursors.space.isDown){  
this.physics.pause();  
pauseGameText.setVisible(true);  
} else if (cursors.shift.isDown){  
this.physics.resume();  
pauseGameText.setVisible(false);  
}  
}

And it works perfectly! 🙂

---

<div class="post-metadata">

**Author:** ![jamespierce](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jamespierce/32/66_2.png) [@jamespierce](https://phaser.discourse.group/u/jamespierce)\
**Post date:** [January 16, 2019, 3:47am UTC](https://phaser.discourse.group/t/how-to-remove-text/742/10 "2019-01-16T03:47:12Z")

</div>

Great! 😊👍

---

<div class="post-metadata">

**Author:** ![damian-pastorini](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/damian-pastorini/32/5058_2.png) [@damian-pastorini](https://phaser.discourse.group/u/damian-pastorini)\
**Post date:** [October 12, 2019, 4:22pm UTC](https://phaser.discourse.group/t/how-to-remove-text/742/11 "2019-10-12T16:22:26Z")

</div>

Probably quite late but unless you want to always re-use the same text object you could also destroy it with pauseGameText.destroy(), and not need to change visibility.
