I have three states - pause, play and menu state. Do you guys like to create more states for some reasons ?
Also, I would like to know total how many game_states can you create in a slick based game (before it stops working properly)?
I have a loading state, menu state and game state. I have my own GUI system for pause menus and such. There is no reason to have an entirely separate pause state, just call pause() on your container object however you see fit and then resume() when you are done pausing.
My current game has 4;
private static final int splashState = 0;
private static final int mainMenuState = 1;
private static final int mapEditorState = 2;
private static final int playState = 3;
pretty self explanatory what they are.
Another project of mine had more, I gave every menu a state, at the time it made sense because of how different each element was;
public static final int menuState = 0;
public static final int playState = 1;
public static final int dialogState = 2;
public static final int inventoryState = 3;
public static final int characterState = 4;
public static final int reputationState = 5;
public static final int mapState = 6;
public static final int settingsState = 7;
public static final int gameSelectState = 8;
public static final int newGameState = 9;
In retrospect though that was a silly way to do it.
The amount of states relies completely on your project and what it calls for. Normally I start a project by making a Menu State and a Game State and when I Pause and Resume I just make it a boolean and put it in the render method like this:
boolean isPaused = true;
public void render(Graphics g) {
if(isPaused) {
// Draw paused Stuff
}else{
// Draw Game
}
}
public void update() {
if(isPaused) {
// Update paused Stuff
}else{
// Update Game
}
}
My game has 2 states:
private static final int singleplayer = 1;
private static final int coop = 2;
Should probably be noted the amount of states you need really depends on the complexity of your game, and what that genre calls for. I’m not sure if there’s really a “correct” answer.
My current game has 0 states. The states are the outcome of what current “View” is on top. (“View” as View in android UI programming)
For example, when you start the game, the top View is MainMenu, so I guess you could say that the state is “mainMenu”.
When you click on play, MainMenuView gets removed and a GameView gets added, which contains game UI elements as well as actually rendering the game.
If player wants to pause, PauseMenuView is added on top of GameView, which creates a “pauseState”.