Hi folks,
Most of the simplest examples of Java2D games have something like:
public void run() {
while (running) {
gameUpdate();
gameRender();
paintScreen();
}
}
In each method you have what you need to update, render objects and paint screen. This is very simple and nice when you are showing how to make a game and only have one screen. What about when you have more screens? (menu, Single player mode, multiplayermode, options, etc).
What is the best way to organize this so that each one of this methods knows what to do depending on which part of the game you are?
My initial thought was to create a State class. Each different part of the game would extend from state and then you would have something like this:
public void run() {
while (running) {
state.gameUpdate();
state.gameRender();
paintScreen();
}
}
Of course this would mean that the state variable would change inside update sometimes so this might create some problems.
What do you guys think of this? In your experience what is the best way to control the flow of these things?
Thanks