LIBGDX para Android – Tutorial 41 – Pantalla de Carga – How to make games Android


Well, the last thing left for us to prepare before we can export our game is to create the screen that I promised to load resources. You see I’ve created Menu Screen, a screen similar to the Game Over Screen, just change the button is called Play and is placed elsewhere. Also, Game Over Screen’ve put a second button to jump to another menu. We have a detail that I said at the beginning. This Loading the Finish It makes it to load synchronously, ie, stops the execution of the program until all loaded. Instead mola more make an asynchronous loading, to tell the user how it goes. For example, say 30% charged or show a progress bar if you are the original. I want the manager loads of asynchronously, so I’ve created a screen, Loading Screen, which now does not do much, displays a message on screen that says Loading.

It would be nice now that says Loading is to load resources put an asynchronously. To do this I will remove this FinishLoading, and instead say that me loaded one by one. To load resources asynchronously, is simple, all you have to do is, in the render, the method is always executed, call one of the methods that have the assetManager class update (). This method is particularly concerned with load a resource, and returns true when everything is finished being loaded, that is, I should put it in an if to detect when I finished loading, because if returns true is that he is ready, and if it returns false, that things are loaded.

Why should we put it in an if? So if you have not done us show the progress of the load and if it is over we will take you to the menu screen, for example game.setScreen (game.menuScreen). If you have not finished loading, I can do It is ask you to provide me progress directly with getProgress (), which returns a float showing me how it goes the thing. So what I can do mismamente is to take this label I created that is used to display a text label, and update your text; * 100 because progress is between 0 and 1 and I want to spend a percentage.

Thus, when now run this, you will see it will take one second … or even a lot. [Exits an error] Oh, okay, now I will explain why it has burst. What is supposed to do is go loading the screen slowly, resource use, and then skip the screen of game. Why he has burst? Because I’m asking you instantiate MenuScreen me when it is not loaded. In the MenuScreen I access directly to a assetManager resource that is not loaded because it has yet to show the loading screen.

In the same way I access GameScreen things that have not been loaded. I change the order in which it runs. SetScreen should move up, and I’ll make a strategy I do not know if it is correct but it is the one I use, a load in two steps. First, I put the resources in the queue manager. I make the loading screen to fire, and when the screen charging is over, we tell MainGame to make the second part of the load, with a method called finishLoading (). And this second method deals load the rest of screens left and finally put the main game screen. What I have to do is tell that LoadingScreen the game finishes loading resources. If you do not put resources load () and do everything in show (), you will not have this problem, but since I instantiate resources by creating classes I have that problem.

I will spend the float to int to make it look better, because I have seen many numbers. Now it remains to 0, let’s see … [keyboard]. I’m going to pass a variable because it will be easier. I multiply by 100, and then convert to an integer for that decimals are removed. I’ll be wrong with a parenthesis. What I mean is that although it looks very little, there is a percentage that is moving. Now it goes well. I can play, lose, jump to the menu, try again … obviously not the Geometry Dash, but it is very cool to see how to do screen jumps. And with that the prototype is finished. This is the game that bear taking from the first episode in the repository that you have in the description, but now I’ll show you how to export to generate the APK that you can send to your mobile phone..

As found on Youtube