Android game engine LIBGDX Resource Load Progress percentage display case Analysis _android

Source: Internet
Author: User

Because the case is relatively simple, so simply use Androidapplication-> Game-> Stage Build the framework
first, the main entrance, no special

Copy Code code as follows:

public class App extends Androidapplication {
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Initialize Demo
Initialize (new Demo (), false);
}
}

second, the game main class
Here we need the resource loader to manage the resources, here for testing, you can add more pictures to the effect of obvious points. Here we also use the stage and use the adaptive resolution.
The key here is to constantly refresh the resource manager in the rendering method, and get the current load progress and pass it to the stage processing.
Copy Code code as follows:

public class Demo extends Game {
Explorer
Private Assetmanager Assetmanager = null;
Stage Sub Class
Private Scene Scene = null;
@Override
public void Create () {
Build Explorer
Assetmanager = new Assetmanager ();
Load test picture
for (int i = 1; I <= 6; i++)
Assetmanager.load ("map" + i + ". png", texture.class);
Generate stage, 480x800 as base resolution, default extension
Scene = new Scene (480, 800);
}
@Override
public void render () {
Gdx.gl.glClear (Gl10.gl_color_buffer_bit);
Refreshing explorer
Assetmanager.update ();
Gets the resource load percentage, 1 represents 100%
Float progress = assetmanager.getprogress ();
Scene.draw (progress);
}
}

third, stage class
There is no special place, just show the progress parameters obtained.
Copy Code code as follows:

public class Scene extends Stage {
Private Bitmapfont font;
Public Scene (float width, float height) {
Super (width, height, true);
Font = new Bitmapfont (Gdx.files.internal ("F.fnt"), false);
Font.setscale (0.6f);
}
public void Draw (float t) {
Super.draw ();
Batch.begin ();
if (T < 1.0f) {
Font.draw (Batch, "Loading" + (int) (T *) + "%", 20f,
HEIGHT/2F);
} else {
Font.draw (Batch, "loaded successfully", 20f, height/2f);
}
Batch.end ();
}
}

Four, the procedure screenshot

SOURCE download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.