dill pixel uses a simple state management system to manage the different states (or screens)
in your game. For example, a simple game might have a TitleScreen, GameScreen, and GameOverScreen.
Let’s see how we would include those in our game and switch between them.
Creating a Base State
To create a new state, create a new file in the src/states directory. For example, let’s create a BaseState
that all of our other game states will extend. This first state should extend dill pixel’s State class
and for now we’ll just add custom animateIn and animateOut methods that will fade all of our states in and out:
Creating a Screen
Next, let’s create a TitleScreen that extends our BaseState:
Registering States
Once all of the states have been created, they need to be registered with the game. This is done in the
src/Application.ts file:
Switching Between States
To switch between states, use the transitionTo method on the game instance: