Using LoadingGameState


I've been looking at the TestLoadingGameState class, and I was wondering how

I could use LoadingGameState to load models, create spatials, etc… and then

fade into the game/DebugGameState. I didn't really understand how to implement this after

looking at TestLoadingGameState because it just "Thread.sleep(100);"s

Do I put the code here? :

for (int i = 0; i <= 100; i++) {
         if (i == 100) {
            status = "I'm Finished!";
         } else if (i > 80) {
            status = "Almost There!";
         } else if (i > 70) {
            status = "Loading Something Extremely Useful";
         } else if (i > 50) {
            status = "More Than Half-Way There!";
         } else if (i > 20) {
            status = "Loading Something That You Probably Won't Care About";
         loading.setProgress(i / 100.0f, status);


you can remove the sleep calls and replace the status changes with something actually useful…unless of course you like my descriptive progress statements I made. :slight_smile:

Yeah, I know, but what I mean is, where should I put in, say a

Box box = new Box("box1", new Vector3f(), 1.0f, 1.0f, 1.0f);

and its updateModelBounds() and attachChild()s?


Well I am using it with StandardGame and the way I do it is…

public RiseToTheStars(){
      /* Start up a StandardGame and get settings */
      visualGame = new StandardGame("StandardGame", StandardGame.GameType.GRAPHICAL);
      /* Display the loading screen */
      transitionGamestate = new TransitionGameState(RiseToTheStars.class.getClassLoader().getResource(GameConstants.TEXTURE_LOADING_BACKGROUND));
      transitionGamestate.setProgress(0.0f, "Initializing");
      MouseInput.get().setCursorVisible( true );
      /* Build the menu */
      mainMenuGamestate = new MainMenuGamestate();
      transitionGamestate.setProgress(1.0f, "Finished");

This is my a segment of my game main class constructor. As you can see you can stick anything in between these calls - GameState initializations, launching of threads (or waiting for their end). Here is another segment from the same class which I run when I click a button in the GUI - it puts up a loading screen until the game is put into a new state.

public void actionSinglePlayerGame(){
      // TODO: Game setup from GUI
      gameSetup = new GameSetup();
      Thread t = new Thread(new Runnable() {
            public void run() {
               /* Display loading screen */
               transitionGamestate = new TransitionGameState(
              transitionGamestate.setProgress(0.1f, "Initializing...");
              /* Start up the GameServer */
              transitionGamestate.setProgress(0.3f, "Initializing Server");
              gameServer = new Server(Server.ServerMode.SinglePlayer, null);
              /* Creating a GameClient */
              transitionGamestate.setProgress(0.6f, "Initializing GameClient");
              LocalGameClient localGameClient = new LocalGameClient(gameServer);
              /* Starts up the ClientGamestate */
              transitionGamestate.setProgress(0.7f, "Initializing ClientGamestate");
              if (clientGamestate != null) GameStateManager.getInstance().detachChild(clientGamestate);
              clientGamestate = new ClientGamestate(localGameClient);
                transitionGamestate.setProgress(1.0f, "Done");

Nevermind what actually goes on in this method. Just see how lines like this:

transitionGamestate.setProgress(0.7f, "Initializing ClientGamestate");

are used to send update messages to the transitionGameState.

So basically when your question is "I was wondering how I could use LoadingGameState to load models, create spatials, etc...". Well just put that wherever you would otherwise put it - GameState Initializaton or in some separate method.. and just call those ... and in between these calls update the LoadingGamestate.

Oh ok! I get it now. So, you pretty much choose how far you think its done loading. One last question:

What's the difference between Loading and Transistion?

Thanks a bunch for the help!

From the TransitionGameState javadoc:

The transition game state provides additional functionality to LoadingGameState. A background image is now shown during the loading phase of LoadingGameState. In addition, if a lead in game state is provided, the transition state will fade frame the previous game state into the loading state and then fade away. The lead in game state will be deactivated once the transition is complete, but not removed from the game state manager.

It pretty much sums it up - it a loading gamestate with additional gimmics.