Phaser for Beginners

Restarting the game

Until now, we learned how to detect the click / touch on a button, but this time we don’t have buttons on the stage. We will need to trigger a generic click/touch. In the same way Phaser handles generic input on buttons, it also handles generic input events.

Look at these new changes:

Apart from restartGame function which simply restarts the game by calling TitleScreen state after clearing out the arrays, I want you to focus on this line:

Wherever you click or touch the screen, restartGame method will be called.

input.onDown(callback, callbackContext) is fired each time a pointer is pressed down. It runs callback function in callbackContext context).

And finally the game is complete. Anyway, what happens if you removed all tiles before time runs out? You will find yourself looking at a black screen while the timer ticks away without you being able to do anything.

That’s why we are going to add another feature. The last one, in this game.

Download Source

File: restarting-the-game.zip


Next Tutorial →

Giving the game a twist

← Previous Tutorial

Showing Game Over screen

Leave a Reply

Your email address will not be published. Required fields are marked *