I am completely new in game developing and even more new in the use of Libgdx. So far I have successfully done great thing on my game project thanks to all the advices I could have gathered on this forum. I would need your brilliant help once again.

- Context:

I have several TiledMaps and on each one of them, there is an object layer named “trigger”. This layer contains objects with name corresponding to an animation in my code. All the animations of this layer are loaded thanks to TextureRegion.split.

- Issue:

When I load a new map or for instance a new floor in a house, the time spent to preload the animations of this new floor is too high. Here are the tests of the time spent to load 3 animations of 4 frames each and dimension 64x64 pixels (corresponding to 16 tiles):

  • 0.7 sec on a Samsung Galaxy S6 (this is far too much for a powerful device and only 3 animations).
  • 1.1 secs on a 4 years old Samsung Galaxy Note2.
  • 2.2 secs on a 4 years old Sony Xperia M (pretty old and powerless though).

Here is the logic of my gamescreen class: GameScreen logic

- Possible solutions:

1) Preload all the animations of the game in the OnCreate and loading screen:

Far from being a good idea with my current game architecture. I expect having 300+ animations (with the fighting ones, cutscenes…). With above tests, it would take 3+ minutes on a powerful device as the Samsung Galaxy S6 for instance.

2) Preload new map animations in another Thread when the user is approaching a teleport trigger:

It will be a good idea on device with good double core CPU but I am afraid of a big FPS drop on single core device or not good double core CPU (like double 600Mhz ones).

3) Label a group of animations with a level-flag and preload them only if level flag changes:

For instance: Level1 flag for 2 exteriors which contains 10 interiors (houses for example)

Level2 flag for 1 exterior and 6 interiors.

On that example, it will just require to preload and having a loading screen when we change of level but with the current architecture of my game code, it will still be a lot of time consuming.

If there is 20 animations and 20 fights animation per level it will be still 40 animations which represent about 7-9 sec on Samsung Galaxy S6 without including sounds loading…

4) Refactor all my code and include logic I was not aware of.

I think it is the best option here. I heard of AsseManager for instance but I have no idea how it is working with Animation object.

Thank you all for your help in advance!

  • 3
    \$\begingroup\$ Did you profile your level loading method to see where the bottlenecks are? Maybe you can optimize something right there. \$\endgroup\$
    – Philipp
    Oct 5, 2016 at 10:45
  • \$\begingroup\$ Thank you a lot for the tip Philipp. I will profile my code this evening and it will definitively give me many clues where I need to optimize my code. But after a lot of thought, I think I need to go for a full refactor of my code and load a bunch of animations with the same flag into an HashMap in my onCreate method. That way I will lose some time at the loading screen but gain so much at every screen switching. I will give you new information which can help further user after I refactored my code. \$\endgroup\$
    – Matteo
    Oct 5, 2016 at 16:41

1 Answer 1


Thanks to Philipp's advice, the profiler made me found that I was calling tmx.loader in a forgotten loop somewhere (I was so stupid back then).

By correcting it, my loading time went from 0.7 sec on my S6 to 0.02. Thank you so much.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .