A scene restarted but the image is still display

Hi everyone,

I tried to restart a scene with a new data. I found that the timer event on that scene reset correctly but the images from the old scene still display instead of new image I want to render. Is this a bug? Here my code:

        // I have 2 scene: Menu and Play. 

        // The Menu scene have a Play button, when clicked, game moved to Play scene

        this.PLAY_BUTTON.on("pointerdown", function(pointer){

            if(this.FIRST_TIME) {

                this.scene.start(CST.SCENES.PLAY, this.SELECTED_TYPE);

                this.scene.setVisible(true, CST.SCENES.PLAY);

                console.log('first load');

            } else {

                if (this.SELECTED_TYPE != this.CURRENT_TYPE) {

                    this.scene.stop(); // stop the menu scene

                    var getPlayScene = this.scene.get(CST.SCENES.PLAY); // get the play scene

                    getPlayScene.scene.restart(this.SELECTED_TYPE); // reset the play scene

                    this.scene.setVisible(true, CST.SCENES.PLAY);

                    console.log('update');

                } else {

                    this.scene.stop();

                    this.scene.resume(CST.SCENES.PLAY);

                    this.scene.setVisible(true, CST.SCENES.PLAY);

                    console.log(

                        'resume'

                    );

                }

            }

        }, this);

    }

Please, put the piece of code that you call to restart scene.

1 Like

I update my code to question. Please review!

Ok. Thanks.

Some more questions:

  1. How many scenes do you have in the game?
  2. What scene this code is inside?

Maybe this example could help you with this problem

  1. I have only 2 scenes: Menu Scene and Play Scene
  2. This snippet is in the Menu Scene

Well,
My suggestion is to keep the code that call play scene in the “create” method of the menu scene and put both codes that call the menu scene and that call restart play scene inside the “create” method of the play scene.

Of course, you will need to insert one button in each scene.

Obs:
I don’t use scene.setVisible(…) in my games, as the example didn’t mention that to change scenes.

And I think you don’t need to call scene.stop() before start another scene.

Hope this help!

Yeah, I put both in the create() method. The setVisible() mehthod I use because I have button to click back to Menu Scene from Play Scene.

The problem is, although the timer event reset correctly but the image in the old screen still display

Ok. Can we keep this conversation by email?
I think it could be more productive. My email is thieberson@outlook.com

1 Like