简体   繁体   中英

LibGDX Problems with textures in 1st launch after installing

I have a problem with my android app created with LibGDX. After 1st launch part of textures in game just disappear and only after relaunch (not hide and reopen) all works fine. It happens only 1 time currently after 1st launch after installing. If installing on installed app, all works fine.

I use atlas for textures, it is 2048x2048. In project I use AssetLoader class with static objects. I saw some tips, that problem may be with static, but then why part of textures normally load?

If somebody had this kind of problem give an advice.

This is called context loss . Textures you load and create are unloaded automatically when you hide, and some of the context are lost between hide and reopen. Relaunching or killing active app after hide will destroy current JVM and when you open again it will be fresh launch and everything works fine.

To avoid this you can manually manage this situation by overriding pause() and resume() methods on ApplicationListener class (which is your main class extending ApplicationListener). You should unload/dispose assets on pause() and reload/create them on resume().

It's not the best but to give an idea you can see an implementation here in question's "EDIT:" part: LIBGDX White textures in the first run on android

But I strongly recommend to avoid static fields and use AssetManager class to load and get Textures, TextureAtlases and such other assets. And let it manage textures for you.

Take a look at: https://github.com/libgdx/libgdx/wiki/Managing-your-assets

I found the problem. It is not in AssetLoader ot Textures. When i load game objects, I also recreate data in phone resources, so when this data exists, all loads fine, but if it is 1st time and it needs to create this data on phone, it causes problems with loading resources. I just move "recreating data" to own function and now all work fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM