Hi everyone,
is it possible to load my InGameState and then pause it for about 10 seconds in the beginning? I want to count down and the start the game after the 10 seconds!
Thanks
You have a physics / animation / AI update, then a render update in your main loop. Inside of the meaty update for your physics and game state, you will have to create a 'switch' statement. You may need multiple instances of this switch statement depending on how you code your update commands, but you will need at least 1. This switch statement will operate off of system INT FINAL name of variables. This allows you to change your game state, and thus change what is happening according to how you want the game to go. For instance, you have
PUBLIC INT FINAL STATE_MENU = 0
PUBLIC INT FINAL STATE_STARTING = 1
PUBLIC INT FINAL STATE_RUNNING = 2
// when you load the game you set mCurrentGameState to the 'default' setting
switch (mCurrentGameState)
{
case STATE_MENU:
//do this (create menu screen and allow your input update and all other updates to opperate in this mode to pick up input from menu and such)
break;
case STATE_STARTING:
//instantiate a countdown object. There are many ways of doing this, it is not hard. When the countdown reaches 0 you change the game state to STATE_RUNNING. This is normally done in the UpdateState method, but jMonkey doesn't explicitly define these update methods, so the chances of you having them already are slim.
break;
case STATE_RUNNNG:
// the code that runs your game, when game is over or closes you change the state to another number and force your code to not execute this main run statement.
break;
}
This is basic game design, jMonkey operates differently from this but my experience with this engine is limited. You mention you want to load your InGameState, so you seem like you have different states set up already. I suggest to go a similar route, either with a switch statement or an if else statement, that when the game loads a variable like gameIsPaused = true.
if (gameIsPaused == true)
{
// Code that renders a count down that when it reaches 0 switches gameIsPaused = false
}
else
{
// Your game code
}
This would allow minimal changes to your code yet get the job done.