Making a loading screen GameState

I've gotten to the point where my game gets a nice black screen for several seconds before it starts rendering.



I have obviously done some research into GameStates, but I'm unsure how to approach this problem.



I was thinking about having a loading game state and switching to the playing game state when the playing game state's initgame had finished, but I'm not sure if that's a feasible approach?

Already an example of that in com.jmex.game.state.load.

I see a class for it, but not an example of it. How do I utilize that?

In eclipse you can search for references to a particular class in the project.

Just highlight the class name , right mouse button -> References -> Project.



Then you see its used in jmetest.game.state.TestLoadingGameState (hey could have guessed that :)).



Its a very useful feature if you want to find your way around in a project you don't know well.

bump  :smiley:

What kind of example are you looking for?

Something that moves a progress bar as another GameState's initGame() is performed.



Basically I want to create the LoadingGameState, then perform the PlayingGameState's initGame(), and have the LoadingGameState turn off when the PlayingGameState's initGame() has been completed.



A progress bar in LoadingGameState would inform you as to how close PlayingGameState's initGame() is to being completed.

Hi, i was bored and made a litte image.



You need 2 Threads, because if you load sth in the OpenGL thread, as long as the init() method the openGL thread is blocked and nothing is rendered. So you use LoadingState, which is in the OpenGL thread, and another state which inits the game in another Thread - so the LoadingState can render the progress.



I recommend to seperate the laoding to an ingamestate and an “ingameLoadingState” - so there are three states: LoadingState: rendering the progress

IngameLoadingState: loads Data like Meshes, initing things, sets the progress in LoadingState. After finished switches Loadingstate and INgameLoadingstate off and the ingamestate on.







Hope this helps and nothing is wrong.



Regards,

snare

1 Like

Snare's Image is great.



Thats exactly what LoadingGamestate or TransitionGamestate (which extends LoadingGamestate) is meant for. :slight_smile:

I display the TransitionGamestate while creating the Menu- InGame-and IntroGamestate:



        TransitionGameState trans = new TransitionGameState(10, ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "loading_black.png"));
        GameStateManager.getInstance().attachChild(trans);
        trans.setActive(true);
        trans.setProgress(0, "Initializing Game ...");
        // init music
        SoundUtil.get().initMusic();
        trans.increment("Initializing GameState: Intro ...");
        GameStateManager.getInstance().attachChild(new IntroState("Intro"));
        trans.increment("Initializing GameState: Menu ...");
        GameStateManager.getInstance().attachChild(new MenuState("Menu", trans));
        trans.increment("Initializing GameState: InGame ...");
        GameStateManager.getInstance().attachChild(new InGameState("InGame", trans));
        trans.setProgress(1.0f, "Finished Loading");
        GameStateManager.getInstance().activateChildNamed("Menu");



By setting progress to 1.0, the LoadingGameState fades out and disables itself.
I am passing the TransitionGameStates reference into the InGameGamestates constructor, so i can further increase the progressbar inside InGameState.

If you use StandardGame this will work out of the Box, if you use BaseGame you need to start using threads.

So the initGame() method for every one of those gameStates is executed when it is attached to the GameStateManager?

well no, GameStates have no initGame Method, they only have a render and update method.

I do all the work (load models etc.) in the GameStates constructor.

… Wow… I figured that out by reading a tutorial on the wiki… that I wrote… I think I need to take a few steps back and relax. I've started to get too detailed and lost sight of the project as an entirety.