# Managing scenes... so confusing to me!

**URL:** <https://phaser.discourse.group/t/managing-scenes-so-confusing-to-me/9854>\
**Category:** Phaser 3\
**Created:** [June 26, 2021, 2:55pm UTC](https://phaser.discourse.group/t/managing-scenes-so-confusing-to-me/9854 "2021-06-26T14:55:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![YanKleber](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/yankleber/32/5152_2.png) [@YanKleber](https://phaser.discourse.group/u/YanKleber)\
**Post date:** [June 26, 2021, 2:55pm UTC](https://phaser.discourse.group/t/managing-scenes-so-confusing-to-me/9854/1 "2021-06-26T14:55:55Z")

</div>

Hi!

I am experiencing some difficulty in the management of scenes particularly in THIS situation…

I have 4 scenes:

**sceneInit**  
**sceneHelp**  
**scenePlay**  
**sceneMenu**

Where “sceneInit” is the main title. This scene has a “play” and a “help” button that supposed to move to **scenePlay** or **sceneHelp** respectively. This is the code I have:

```javascript
// help button -> pops up sceneHelp
this.scene.start('sceneHelp');
// play button -> move to scenePlay
this.scene.switch('scenePlay');

```

In the **sceneHelp** I have a “close” button:

`this.scene.setVisible(false);`

It works fine.

However, in the scenePlay I have a “menu” button that pops the **menuScene** :

`game.scene.start("sceneMenu");`

The issue happens in the sceneMenu where I have a “init” button that supposed to bring player back to the **sceneInit**. My code for this button:

`game.scene.start("sceneInit");`

Instead to move back to the **sceneInit** , however, it will just close the **sceneMenu** and will get back to the **scenePlay** BUT regardless the **scenePlay** is being shown no one of those buttons works. In fact it seems that I can click the buttons of the **sceneInit** that looks like to be under **scenePlay**.

My questions:

1. What am I doing wrong here? (I have the feeling that I am using the scene managing methods kind of randomly)
2. When should I use start, restart or switch?
3. When I move to a different scene what should I do with the current one: setVisible(false) or destroy or what?

Thanks!

---

<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:** [June 26, 2021, 3:27pm UTC](https://phaser.discourse.group/t/managing-scenes-so-confusing-to-me/9854/2 "2021-06-26T15:27:10Z")

</div>

I use

> **[samme/phaser-plugin-scene-watcher](https://github.com/samme/phaser-plugin-scene-watcher)**
>
> Scene monitoring and debugging for Phaser 3. Contribute to samme/phaser-plugin-scene-watcher development by creating an account on GitHub.

for these kinds of problems.

Don’t use `scene.setVisible(false)`.

Don’t use `game.scene`. Use `this.scene` instead.

Generally, you want to first figure out how to enter/exit scenes and then [choose the right methods](https://gist.github.com/samme/01a33324a427f626254c1a4da7f9b6a3#scene-control "Phaser 3 scenes summary: Scene flow") depending on the scene flow.

My guess is that **sceneInit** , **sceneHelp** , and **sceneMenu** should be started, then slept, then awakened. **scenePlay** should be started, then stopped, then started (for replaying); or slept and awakened (when opening and closing the help screen).

---

<div class="post-metadata">

**Author:** ![YanKleber](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/yankleber/32/5152_2.png) [@YanKleber](https://phaser.discourse.group/u/YanKleber)\
**Post date:** [June 26, 2021, 4:35pm UTC](https://phaser.discourse.group/t/managing-scenes-so-confusing-to-me/9854/3 "2021-06-26T16:35:57Z")

</div>

**Samme** ,

I figured this out. I was messing up things. Actually TWO specific things:

1. Sometimes I was using _game.scene_ and other times using _this.scene_. In fact **YOU** already had warned me about not to use game.scene in a couple of my posts. My bad.

2. In some scenes I was using _regular functions_ in the click event of the buttons to start the scenes and in others I was using _arrow functions_.

The solution was indeed to change everything to _this.scene_ and move everything to _arrow functions_. Now it is working as supposed.

_PS: I will check your links to get more secure about using scenes though._

Thanks once more!

---

<div class="post-metadata">

**Author:** ![YanKleber](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/yankleber/32/5152_2.png) [@YanKleber](https://phaser.discourse.group/u/YanKleber)\
**Post date:** [June 26, 2021, 4:47pm UTC](https://phaser.discourse.group/t/managing-scenes-so-confusing-to-me/9854/4 "2021-06-26T16:47:14Z")

</div>

**HOWEVER!** I just realized that it caused me another problem. Now when I start a popup over a scene, my background scene disappear. I figured that if I use launch instead start I can open a scene over a scene:

```javascript
  this.btnLaunchPopup.on('pointerup', (e) => {
            this.scene.launch("scenePopup");
        });

```

But then if I try to start another scene from the popup (launched scene) it will just close the popup but won’t change to the desired scene:

In the popup:

```javascript
  this.btnGoInit.on('pointerup', (e) => {
            this.scene.start("sceneInit");
        });

```

It will only close the launched scene but won’t go to the scene.

Any idea?

---

<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:** [June 26, 2021, 5:09pm UTC](https://phaser.discourse.group/t/managing-scenes-so-confusing-to-me/9854/5 "2021-06-26T17:09:43Z")

</div>

I hope you are using the plugin. Without it it’s a lot of guesswork. 🙂

Remember that `scene.start('key')` is a double operation: it **stops** the calling scene and **starts** the named scene.

> [@YanKleber](#):
>
> It will only close the launched scene but won’t go to the scene.

Whatever scene is visible but shouldn’t be, you need to sleep or stop it.

---

<div class="post-metadata">

**Author:** ![YanKleber](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/yankleber/32/5152_2.png) [@YanKleber](https://phaser.discourse.group/u/YanKleber)\
**Post date:** [June 26, 2021, 5:21pm UTC](https://phaser.discourse.group/t/managing-scenes-so-confusing-to-me/9854/6 "2021-06-26T17:21:06Z")

</div>

I got it now!!! Thanks for the clarification! This is the fix that worked for me:

```javascript
this.btnGoInit.on('pointerup', (e) => {
            this.scene.stop("sceneMain"); // the scene which launched the popup
            this.scene.start("sceneInit");
        });

```

Thanks again! 🙂
