user93796
user93796

Reputation: 18379

Graphics taking 0.5 GB memory in libgdx

I am developing a simple 2D game. I have multiple sprites. Each sprite has around 80 png/frames of 265* 256. I used LibGdx's Texture packer to package the atlas. Am enabling mimap using following code to pac

TexturePacker.Settings settings = new TexturePacker.Settings();
settings.combineSubdirectories = true;
settings.filterMin = Texture.TextureFilter.MipMapNearestLinear;
settings.filterMag = Texture.TextureFilter.Linear;

TexturePacker.process(settings, f.getPath(), outputFolderName, atlasFileName);

Questions:

  1. Are 80 images/frames for single sprite too much?
  2. Is 0.5 GB memory usage too much for a simple game like Fruit ninja?
  3. How can i reduce my memory usage?
  4. Any other things i should try?

Update1: Here is the the screen shot taken from android profiler.enter image description here

Upvotes: -1

Views: 180

Answers (1)

VILLAIN bryan
VILLAIN bryan

Reputation: 741

80 frames is kind of a lot but that number has never been a problem in my projects. That said, most of our 60 frame pre-rendered animations are small, like an icon flashing graphic in 48x48 segments, with one sheet (so there is minimal context switching). This has never been a performance issue for us ... BUT you saying 256x256 scares me a little, especially if it is uncropped and a lot of pngs are created!

While my projects have sprites of similar frame numbers, they have been optimized via the Texture Packer. Make sure you have Trim mode set to "Trim" and that it isn't "None" (the setting is near the bottom under Sprites). This setting will de-homogenize the 256x256 into smaller pieces if at all possible, reducing the number of total sheets and texture bindings (I think, and also fewer context switches) .. I'm not totally sure how you packed your sprites or if they can even be trimmed, but this could potentially be a performance life saver.

Let me show you an example:

Before enter image description here

After

enter image description here

Also if you provided the code in how your animations are created, we could double check to make sure you aren't binding 80 Textures when only 1 would be needed. I create my animations via the following process:

TextureAtlas atlas = assetManager.get(atlas_name);
Sprite[] spriteFrames = new Sprite[numFrames];

for (int index=0; index<numFrames; index++) {
    if (atlas.findRegion(lookup_name, index) == null)
        Engine.console("[ERROR] problem loading and finding region for " + atlas_name + " " + lookup_name + " index: " + index + " not found in spritesheet .. fix immediately");
    else {
        spriteFrames[index] = atlas.createSprite(lookup_name, index);
    }
}
Animation<Sprite> animation = new Animation<Sprite>(timeBetweenFrames, spriteFrames);

I hoped this helped providing some insight.

Upvotes: 0

Related Questions