Problem switching / restarting scene

Hi everyone !
I experiment a strange problem, when I try to transition to another scene using this.scene.start(‘nameOfTheScene’);
I get a black screen without the text contained into this scene.

Also, if I try a this.scene.restart() I have the following errors :
TypeError: this.frame.source is null
TypeError: this.source is null

Does someone already experiments problems like this ?
the pen (https://codepen.io/paulbonneau/pen/OrKgvR)

I use matter.js as physics engine for the record

From a quick glance, it looks like your scene keys don’t match. You might also want to log out your scene list order.

Even when I’ve got the exact same string for the key i call in my transition / switch. I get a black screen.

I also tried to match the key name with the “Class” name of my scene but it doesn’t solve the problem.

How the scene order could affect scene called with keys ? I tried to modify the order but it doesn’t change the behavior.

Hi ! Thank you very much for your correction. If I understand it correctly, the problem was that I didn’t used a capital S for Phaser.Scene in my scene declaration.

And thanks for the debug method of scene, I didn’t find the way to debug efficiently in Phaser 3:
callbacks: {
postBoot: function (game) {
game.scene.dump();
}
}

A last question. When I try to restart my first scene (the one where the game is) I get the following error :
TypeError: this.frame.source is null
TypeError: this.source is null

Do you know where could it come from or at least how I could debug this one ?

Have a look at the following two World Issues about scenes. This might help you to understand the concepts behind scenes.

That’s happening because the destroyed text object is still receiving the scene’s addScore event and trying to draw. Do something like:

this.events.off('addScore');
this.scene.restart();

Scene event listeners aren’t cleared when the scene is shutdown (stopped, restarted). It’s a tricky point.

2 Likes

I know this is an old post, but you just saved my day. Thanks a lot for this reply!