Reputation: 67
In my libgdx game I use a lot of “heavy” graphics. It is a huge canvases with many frames of animation. This canvases have resolutions greater then 1000*1000. There is a lot of graphics like this (function loadTextures() is about 200 lines of code). Even on high-end devices, loading the game takes a lot of time, and at most weak devices game can’t even load and hangs on loading graphics.
How to optimize all this stuff? How do you solve issue like this?
Upvotes: 0
Views: 1184
Reputation: 8113
First make sure that your textures never exceed the size of 1024x1024 and always use power of two dimensions. If you have multiple smaller (or non POT) textures, pack them into one larger texture (of 1024x1024 max).
Having many textures (of 1024x1024 each) will eat lots of memory, so you should probably reconsider your approach. For example you can load/unload textures just in time (using AssetManager) at certain points in your game (call System.gc(); afterwards, to keep the garbage collector somewhat under control).
If that's not a possibility (e.g. all textures are used for the same animation), e.g. consider downsizing the textures, only animating the parts that actually change or using boned animations (for example, look at Spine, http://esotericsoftware.com/).
The best approach for your situation may vary. But in general, consider the following guidelines if you need more than one texture:
Upvotes: 1