AssetManager in LibGDX

I am trying to use the AssetManager class in LibGDX, and I understand how it works, but I am trying to implement a loading screen. I followed the AssetManagerTest.java file here , but I'm having difficulty trying to figure out how to make it work correctly. Can someone point me in the right direction? My goal is to load resources (textures, sounds, fonts, etc.) and update the panel with a percentage full on the screen. I do not understand ResolutionFileResolver and Resolution[] in the link I provided. What are they for? My goal is to maintain a static class that can give me access to all the assets I need in my game from any screen. Is there a preferred method for this? Thanks.

+6
source share
1 answer

After looking at the source ResolutionFileResolver , as well as other "resolvers", I think that this is just a way to load textures that best fit the screen resolution, but the match is based only on file name patterns.

So, in AssetManagerTest he got textures for screen sizes of 320x480, 480x800 and 480x854. It looks like each texture group should be in a directory called β€œ.320480” or β€œ.480800” or β€œ.480854” (although the name can be whatever you want, for example, β€œlow”, β€œhigh” and β€œwide” if these are your directories), and it sets all this information when creating an array of resolvers on line 56 of the test.

The advantage of all this is that when he calls manager.load() , he simply selects the file name, for example, "data / animation.png". Then the recognizer finds a texture pack that most closely matches the current screen resolution and loads it.

I think the rest of the example should be pretty clear, at least for the basics of AssetManager . Create a manager, install the bootloader, call load() , call get() to use it, and then call unload() when you're done.

To update the progress bar, you just need to do it manually after each call to download.

And using a static class for asset management is certainly one of the possibilities. Another similar option is to simply use a singleton. He has his own haters, but I think that in a simple project in garbage collection he should be fine, although it is about the same as in public statics.

Another option - perhaps the best? - use a base class that has a static copy of your global globals, and then all other game classes inherit from it. This is the approach used on Replica Island. See base class and object registry . Replica Island is well-commented and worth checking out games for Android and Java.

+7
source

Source: https://habr.com/ru/post/910182/


All Articles