Join Joseph Labrecque for an in-depth discussion in this video Detecting game-over, part of HTML5 Game Development with Phaser.
- View Offline
…Once all of our bunnies are lost to collisions,…there's nothing more to defend, so game over.…We need to set a boolean to keep track of whether the game has ended or not, and…can use this variable throughout our game to control when certain actions occur.…So, at the top of Game.js, we're going to set that boolean as this.gameover.…Within our create function, the first thing we want to do is make sure…that this dot game over is set to false before anything else happens in our game.…
In certain conditions, we're going to want to restrict whether something happens or…not based upon game over,…because if the game is over we don't want to respond rocks anymore.…We don't want to allow the user to fire explosions anymore.…It doesn't make sense.…So, let's go down to our respawnRock function.…That's right here.…And all we need to do is wrap this in an if statement.…So we'll say if this.gameover is equal to false.…Then we want to be able to actually respawn the rocks.…If game over is true, we don't want this to ever execute.…
- Downloading the Phaser framework
- Creating your first Phaser project
- Building the preloader and menu states
- Creating and spawning entities
- Working with particles and emitters
- Detecting and handling collisions
- Detecting "game over"
- Adding sound effects and text
- Preparing for mobile deployment