9
votes

Is there any method to pause a running game and resume back (using a button) in Phaser-3 framework? The one given for Phaser-2 is not working.

3
check their docsMargon
@Margon That just gives you the event of when it has been paused, it will not pause the game.Totty.js
Pausing the game is done automatically when moved to the background (like visiting another tab). I haven't found a way to pause the main loop, but what I did find is the method to sleep the main loop (the game loop iterates through each scene loop). So if you want to pause all scenes without looping through active scenes, you can do game.loop.sleep(); and game.loop.wake(). This will stop all scenes from updating, but the scenes will stop before their active property changes, so just make sure to check the game loop status along with the scene status if needed.Harry Scheuerle

3 Answers

12
votes

In phaser3 you can have several scenes running in parallel. So you can create a new scene with the resume button and pause the current scene. If you have 2 scenes A e B you can do:

# In scene A
this.scene.launch('sceneB')
this.scene.pause();

# Then in sceneB, you can return to sceneA:
button.on('pointerdown', function() {
    this.scene.resume('sceneA');
    this.scene.stop();
})
3
votes

Call game.scene.pause("default") if you have only the default scene. If you have more call it like this game.scene.pause(sceneKey).

Docs at: https://photonstorm.github.io/phaser3-docs/Phaser.Scenes.SceneManager.html

0
votes

If you just want to freeze a character, you can use this.sprite.body.moves = false;