# How to load scenes correctly?

**URL:** <https://phaser.discourse.group/t/how-to-load-scenes-correctly/6689>\
**Category:** Phaser 3\
**Created:** [June 15, 2020, 2:30pm UTC](https://phaser.discourse.group/t/how-to-load-scenes-correctly/6689 "2020-06-15T14:30:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrAmericanMike](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@MrAmericanMike](https://phaser.discourse.group/u/MrAmericanMike)\
**Post date:** [June 15, 2020, 2:30pm UTC](https://phaser.discourse.group/t/how-to-load-scenes-correctly/6689/1 "2020-06-15T14:30:19Z")

</div>

I am new to Phaser and I’m not sure I’m handling loading scenes correctly.

I have a LoadScene where once it reaches create() I send it to load a MenuScene by using

```
this.scene.start(STATIC.SCENES.MENU, { data: 0 });

```

Ignore the {…] that was for some testing.

From that Menu Scene, I have 3 buttons to “Play”, “Settings” and “Credits”

I load those on mouse and keyboard inputs with

```
this.scene.start(this.scenes[index]);

```

“scenes” is just an array with the keys for each scene

```
this.scenes = [STATIC.SCENES.PLAY, STATIC.SCENES.SETTINGS, STATIC.SCENES.CREDITS];

```

Finally on this scenes I have for now just a “back” button that is loading the Menu Scene again with

```
this.scene.start(STATIC.SCENES.MENU);

```

As far as I know from what I read is that using start method stops the current scene we are on. However, when I go back to the main menu, something weird happens.

My buttons for “Play”, “Settings” and “Credit” play a sound on mouse over and when selected with the arrows.

On menu first load the sound effect volume is perfect, however after coming back to that scene from the back button on the others, when using the arrows to select the menu options, the sound effect sounds louder and louder (Which makes me think, I’m loading scenes on top of scenes).

While I’m on Play, Settings or Credits, up and down arrows don’t play any effect, so clearly the menu scene isn’t on the back.  
Weirdly enough (or maybe not) when on mouse over, the volume is fine. So I guess my:

```
this.input.keyboard.on('keydown', (event: any) => {

```

Is still running and I’m just adding another listener on top?

Anyone has any idea what could be going on?

Let me know if you need any more of the code.

---

<div class="post-metadata">

**Author:** ![Darko](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/darko/32/3335_2.png) [@Darko](https://phaser.discourse.group/u/Darko)\
**Post date:** [June 15, 2020, 9:18pm UTC](https://phaser.discourse.group/t/how-to-load-scenes-correctly/6689/2 "2020-06-15T21:18:51Z")

</div>

Hi, just as an idea… maybe for moving between menus is a better idea to use `this.scene.switch()` as I run with a similar issue testing something like this and I ended using “switch”.  
If not, would be nice if someone more used to work with menus or with better knowledge in scene best practices bring some light to this…

---

<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 16, 2020, 2:42pm UTC](https://phaser.discourse.group/t/how-to-load-scenes-correctly/6689/3 "2020-06-16T14:42:54Z")

</div>

You can check

```javascript
console.log(this.input.keyboard.listenerCount('keydown'));

```

before adding listeners.

---

<div class="post-metadata">

**Author:** ![MrAmericanMike](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@MrAmericanMike](https://phaser.discourse.group/u/MrAmericanMike)\
**Post date:** [June 19, 2020, 10:41pm UTC](https://phaser.discourse.group/t/how-to-load-scenes-correctly/6689/4 "2020-06-19T22:41:38Z")

</div>

Using switch solved the problem. 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 20, 2020, 12:19am UTC](https://phaser.discourse.group/t/how-to-load-scenes-correctly/6689/5 "2020-06-20T00:19:09Z")

</div>

I’m actually curious what was wrong. The scene removes its keyboard event listeners when shut down (before restarting), so I don’t think those should stack up.

---

<div class="post-metadata">

**Author:** ![MrAmericanMike](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@MrAmericanMike](https://phaser.discourse.group/u/MrAmericanMike)\
**Post date:** [June 20, 2020, 11:09am UTC](https://phaser.discourse.group/t/how-to-load-scenes-correctly/6689/6 "2020-06-20T11:09:22Z")

</div>

I don’t think they were stacking neither, and the console didn’t show duplicate responses. I wonder if someone can reproduce it to confirm the weird behavior and understand better where the problem comes from.
