1

I've started using LibGDX some time ago and I was making a test project to get used to this library. I've created some images and added them to the assets folder and loaded each image as a Texture using the AssetManager. Everything was working fine and I had 60 FPS.

I wanted to work in a more efficient way so I packed all my images into an atlas using the TexturePacker tool. I loaded the atlas using the AssetManager again and started using TextureRegions instead of Textures.

After this change I've started to notice sudden drops in FPS from 60 to 50 and even 30 once. I've tried to change the pixel format to RGBA4444, I've made sure that the min and mag filter were both seth to Nearest, but still I see those annoying frame drops.

I'm not doing anything heavy in the game itself, it's currently some actors in a stage. I got some MoveActions and Animation, but nothing special yet.

Does anyone have a clue what can cause the FPS drop?

Thanks

Elad92
  • 2,471
  • 4
  • 22
  • 36
  • One possibility is that you are creating a lot of new objects in the render loop and so there is a short pause whenever the GC has to clean some of them up. My rule of thumb is to never use the `new` keyword in the `render` method or anything called by it. Which is overkill, but it keeps me from making the mistake of creating a bunch of objects that will quickly fall out of scope. – Tenfour04 Oct 02 '14 at 12:52
  • The Pool and Pools classes really help with avoiding GC as well. They have been set up to automatically create pools of objects for any class. When you need a new object in your render loop just call `Vector3 tmpVec3 = Pools.obtain(Vector3.class);`, for example, to get a Vector3. And when you're done with the object just return it to the pool instead of letting the GC clean it up: `Pools.free(tmpVec3);`. – Tenfour04 Oct 02 '14 at 12:55
  • Using a texture atlas instead of a texture for each image will never make fps drops. this is for the way OpenGL draws. – Daahrien Oct 02 '14 at 14:12
  • Use one of the Android profiling tools to see where your time is going. – P.T. Oct 02 '14 at 14:47

1 Answers1

1

Thanks for all the comments, I've solved the problem. I called AssetManager.update on render, and when it finished loading I loaded all the regions into static fields for easy access.

The problem was that it was called every time even after I populated all the fields. I guess all the repeating findRegion calls made those hiccups. So basically the problem was too much processing in the render loop.

Hope it will help someone.

Elad92
  • 2,471
  • 4
  • 22
  • 36