Jan Lovšin
Jan Lovšin

Reputation: 171

How to obtain a "loading screen" using libgdx?

I have been wondering how to create a loading screen. If I use

while (!manager.update()) 

the game will never render. Then I had an idea if I would call in the while loop manually the render method. Like:

while (!manager.update()) 
    render();

it would probably work. Then I could also just create another thread and render in besides this thread? What is the best solution?

Upvotes: 5

Views: 2495

Answers (2)

Pookie
Pookie

Reputation: 1279

A very simple solution is to draw over and not render. Let me elaborate, you will stop rendering the game, render a loading screen while it is loading, then give it about 2 seconds to render the new screen like so:

    if(renderingGame){
            //render all your stuff

            if(loading){
                renderingGame = false;

           }else if(loading){
                renderLoadingScreen();
           }else(!loading){
                elapsedTime += Gdx.graphics.getDelta();


        }
           if(elapsedTime > 3)
                renderingGame = true;

Upvotes: 1

Hllink
Hllink

Reputation: 918

You really should take a look at this wiki page, your render method should be something like this:

 public void render() {
      if(manager.update()) {
         // we are done loading, let's move to another screen!
      }

      // display loading information
      float progress = manager.getProgress()
      ... left to the reader ...
   }

Upvotes: 5

Related Questions