0
\$\begingroup\$

I'm an Android dev who's trying to get into game dev.

As the title says, I'm trying to load a hundred PNGs as an animation, fullscreen on Android, but no matter what I try, I always getting out of memory errors, ,or heavy lags.

I've tried different engines, as well as different approaches to loading assets, here's a list of what hasn't worked :

1 - Libgdx :

  • Using Atlas textures, loaded in splash screen using the assets manager : Process killed with no errors after loading 20 2048*2048 Atlas.
  • Atlas Textures without Assets Manager : Huge Lag before the animation actually starts.
  • Sequence of PNGs using Assets Manager : Crash with explicit OOM.

P.S : All Atlas files have been compressed to the Max. Average Final file size is about 1.5MB.

2 - AndEngine :

  • Using Atlas Textures : So far I haven't been able to load multiple atlas pages. Seems like Andengine can only load single page atlases.

  • Using createTiledFromAssetDirectory() and loading every single PNG from the assets directory to a BuildableBitmapTextureAtlas : Seems like I need to set a fixed size for the BuildableBitmapTextureAtlas, and again, it doesn't support multiple pages. So I'm stuck with loading all my 100s of assets, into a single 2048*2048 atlas. Not what I'm looking for.

Please keep in mind all PNGs are exactly 480*800px and I'm looking to play those in full screen android devices. Each PNG is about 20KB - 40KB after compression with PNGQuant.

\$\endgroup\$
5
  • \$\begingroup\$ Can't you simply create a regular movie? \$\endgroup\$
    – Elva
    Oct 21, 2016 at 14:52
  • \$\begingroup\$ 1. Make a GIF 2. Play the GIF 3. Profit \$\endgroup\$
    – DH.
    Oct 21, 2016 at 14:52
  • 1
    \$\begingroup\$ 100 * 480 * 800 * 4 (byte per pixel) = 146 MB. That's quite a lot for the limited VRAM of a smartphone. \$\endgroup\$
    – Philipp
    Oct 21, 2016 at 15:02
  • \$\begingroup\$ I'm not trying to do the animation as GIFs (Quality Downgrade) or Video. I reverse engineered other games doing similar animations and I could see a thousand single images for the animations. That's what I'm trying to replicate here. \$\endgroup\$
    – AppyG
    Oct 21, 2016 at 15:51
  • \$\begingroup\$ Try to pallette your images to reduce memory usage, the less colors you have the less memory it will take, that's what these other games probably did. \$\endgroup\$
    – rlam12
    Oct 21, 2016 at 22:54

1 Answer 1

1
\$\begingroup\$

Don't.

It sounds like you're basically playing a full-screen movie. So one option is to use a movie file. Not only is this more straightforward, but since move movie file formats utilize compression it will save you a fair bit of space.

A second option is to break the scene you're trying to display up into smaller parts. If every pixel of the sequence you want to play changes every frame, this won't help you, but chances are that's not the case. If the background is mostly static, you can load one background frame, and a series of (smaller) frames for the animated components that sit on top of the background.

A third option is to stream the sequence in. Load the first few frames of the animation and play them, discarding them from memory immediately after displaying them and loading the pending frames in a background thread. If the animation is long enough and you can perform the IO fast enough (which is probably doable since you aren't doing anything else but playing this animation), it could work.

\$\endgroup\$
2
  • \$\begingroup\$ Thank you for the answer. I actually reversed engineered a few of the games on the play store that are doing similar animations to what I'm trying to achieve, and by digging into their assets I could see they have thousand of individual 480*800 single frames. So that's what I'm trying to replicate, not interested in video or GIF. The third option sounds like what I'm looking for but I can't seem to figure out how to do that, is there any code sample you can direct me to ? \$\endgroup\$
    – AppyG
    Oct 21, 2016 at 15:49
  • \$\begingroup\$ Okay so I've implemented the third option, and it actually works, no more OOMs after disposing of frame - 1. However, the caveat is that I cannot pre-load all my textures in a splash screen with the assets manager, and thus whenever a new animation is supposed to start ( on click ), it takes at least 1 second to load all 100 Frames into the animation array. I'm selecting this as the accepted answer since it fixed my original problem. Thanks again P.S : I used libgdx to do this. \$\endgroup\$
    – AppyG
    Oct 21, 2016 at 17:12

You must log in to answer this question.

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