Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pause and Resume Game in Phaser 3

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.

like image 520
Akash Abi Avatar asked Jun 22 '18 12:06

Akash Abi


People also ask

How do you pause scenes in phaser?

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

How to pause game in phaser 3?

Then you check if the button p is pressed. If yes, then you toggle the pause value (pause = ! pause). As for the text, you can either use the text method or use an image.


3 Answers

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();
})
like image 106
Ventoh Avatar answered Oct 15 '22 00:10

Ventoh


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

like image 38
Totty.js Avatar answered Oct 15 '22 00:10

Totty.js


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

like image 38
ubershmekel Avatar answered Oct 14 '22 23:10

ubershmekel