State Based Games

From Slick2D Wiki
Revision as of 17:09, 8 August 2013 by Sigtau (Talk | contribs)

Jump to: navigation, search

The BasicGame class can get you a long way with simple game development. However, when games become more complicated it's often useful to separate out the different parts into separate classes with logic and rendering. These different parts are referred to states, as in the state a game is in.

In Slick this concept is supported via the Game implementation StateBasedGame. This game implementation proxies the render and logic methods to the “current” state. The states available and current are set externally by supplying implementations of the GameState interface. However, a convenience implementation of State is supplied, analogous to BasicGame, named BaseGameState.

The GameState is similar to the game interface, in that it has an init, render and update methods. However, the state based game can hold multiple of these state implementation which it can then switch between. In this way the render and logic associated with each facet of the game can be separated into different classes.

As an added bonus, when swapping between these game states a visual effect can be applied to make the swap seem more fluent. These visual effects are referred to and implemented as Transitions.

See Also