Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain a "loading screen" using libgdx?

Tags:

android

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?

like image 929
Jan Lovšin Avatar asked Apr 26 '16 14:04

Jan Lovšin


2 Answers

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 ...
   }
like image 74
Hllink Avatar answered Oct 01 '22 09:10

Hllink


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;
like image 29
Pookie Avatar answered Oct 01 '22 09:10

Pookie