From the Perplexing Technology blog: "Developing a game using states, allows you to organize your code, while also adding a more complete and dynamic gaming experience for the player.
In this tutorial I’m going to walk you through creating a very simple JavaScript game using game states and the Phaser framework.
Using states allows you to break your game up into smaller pieces that can handle different mechanics of the game, such as a menu. In this tutorial we’re going to create five states that will function as follows:
-
The Boot State - We are simply going to start the physics system, and then call the Load State
-
The Load State - We display a ‘loading’ text, load our assets, and call the Menu State
-
The Menu State - We display the game name, get player input and call the Play State
-
The Play State - This is where the game logic is actually handled. When the player wins (there is no way to lose), we call the Win State
-
The Win State - This state will display a simple ‘You Won’ message, get player input, and re-call the Menu State"