How to resume a scene outside of Phaser?

Hello,

I need to resume a scene from outside Phaser.
Is it possible ?

Here is a pen : https://codepen.io/Tonio24100/pen/QoLLJq
L. 25 : this.scene.pause();
L. 63 : game.scene.keys.KeySceneA.resume(); (doesn’t work, What is the right way ?)

Thanks in advance,

Anthony

game.scene.keys.KeySceneA will give you the Scene object for the scene, but the actual resume method in the Scene Plugin, which is available either as scene or sys.scene on the Scene object. Try game.scene.keys.KeySceneA.scene.resume();.

Thanks Telinc1

It doesn’t work too. I also tried int the codepen with :

game.scene.keys.SceneA.scene.resume();

But it doesn’t work again.

I took another look at the example; your scene’s key isn’t SceneA, it’s KeySceneA - the argument you give to the constructor of Phaser.Scene. On theory, it should be game.scene.keys.KeySceneA.scene.resume();.

The actual problem, apart from the incorrect scene key and function, is that scenes are initialized after the game boots, not when the game is created. You should run your resume function in the postBoot callback of the game config. I’m not sure if this will have an effect, either, because you pause the scene in its create function, so postBoot could be too early.

The better question here is why you want to pause your scene like this and then resume it. It seems quite weird without any context.

Thank you Telinc1 for your detailed answer.

My phaser game is in an hidden DIV and I have an animation at the start of my phaser game.
That’s why I need to pause it immediatly (to stop the animation).
And I need to resume it when I will show the DIV with (to start the animation).

In the codepen, this is the template I used for my game.

Do you think it’s possible ?

Maybe it’s possible to pause the entire game ?

You can pause the entire game by pausing the Time Step, available as game.loop, with its sleep method, then resuming it with the wake method. You’re going to have to play around with the timing here because postBoot runs before the Time Step starts, so sleeping it will have no effect. A method that worked in the CodePen was to sleep the Time Step in the init method of the Scene, then wake it later.

Top !
Thank you very much @Telinc1