Exploring Phaser 3 with a Game: Adding Multiple Scenes
In part one we had made peg solitaire game in Phaser 3 which was a single scene game. We will further explore Phaser 3 and use multiple scenes. Most of the times games would have a menu screen and a separate game screen. Many games would also keep a separate screen once the game is over so let us make changes in our game to add another scene which will be called once the game is over (either game is finished or there are no further moves). We are going to define our “game over” scene as following class GameOver extends Phaser.Scene { constructor() { super(“GameOver”); } preload() { this.load.image(“restart”, “images/restart.png”); } create() { var gamedata = this.registry.get(‘gamedata’); this.add.text(140, 100, ‘Game Over’, { font: ’42px Courier’, fill: ‘#000000’ }); this.add.text(155, 160, ‘Moves: ‘ + gamedata.movesCount, { font: ’42px Courier’, fill: ‘#000000’ }); if (gamedata.remainingPegs > 1) { this.remainingPegs = this.add.text(30, 220, ‘Remaining Pegs: ‘[…]