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:
// 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:
What am I doing wrong here? (I have the feeling that I am using the scene managing methods kind of randomly)
When should I use start, restart or switch?
When I move to a different scene what should I do with the current one: setVisible(false) or destroy or what?
Generally, you want to first figure out how to enter/exit scenes and then choose the right methods 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).
I figured this out. I was messing up things. Actually TWO specific things:
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.
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.
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: