gamestates - Vrekt/Lunar GitHub Wiki

GameStates are the core of your project. GameStates hold much of your games data for that level/state. GameStates also include instances to your worlds and entities. Below are the abstract methods you must implement when creating a new GameState.

  • onDraw(Graphics graphics); Handles drawing things to the screen.

  • onTick(); Handles updating things, such as entities, worlds, etc.

GameStates also have a priority assigned with them, this is defined as a number. 0 would be the lowest priority, which would get called first.

Here is an example of a basic GameState.

public class MainState extends GameState {

	public MainState(int priority) {
		super(priority);
	}

	@Override
	public void onDraw(Graphics graphics) {
		// update game graphics
	}

	@Override
	public void onTick() {
		// update entity/world logic.
	}
}

Now you can push it to the game stack.

game.addToStack(new MainState(0));