I have a 2D game that uses many sprites. My game has 15 characters, each character has ~7 animation sequences in 6 different directions, and each sequence has ~9 frames. (5000+ frames to save you the calculation.)
Currently I’m striping whitespace and packing the sequences into 1024x1024 images. It takes ~120 images to fit everything. I never split a sequence across images. Just before the first frame of a sequence is needed, I load the image for that sequence if it isn’t already loaded. After the animation, if no active sequences need the image, I unload it.
This works OK most of the time, but occasionally fails. Imagine a group of 6 characters all die at the same time. If the death animations happen to be on different images that aren’t loaded, the game pauses while the 6 images are loaded. The pause is extremely noticeable, even on good desktop hardware.
I’m targeting both the desktop and Android with this game. I haven’t tried it yet, but I’m guessing that even if only one image needs to be loaded, on Android the pause will be noticeable. Certainly if 6 are loaded at once, Android will be brought to its knees.
What do you think would be the best approach for my animation system? Maybe you guys have some sage advice or tricky tricks for this problem.
I could store one sequence per image. This should reduce the load time, at the (possibly negligible) cost of more video memory since the images are unlikely to be powers of two and this approach guarantees the use of one texture per active sequence. I envision the typical number of different simultaneously active sequences would be ~30, with a max of maybe ~60.
The actual loading of an image is done by this IMGDecoder class. Possibly this could be optimized. Would it be worth doing pure Java JPEG decoding to load the image directly into a ByteBuffer OpenGL can use?
I could decode all ~120 images before hand, so I just have to read the bytes and hand them to OpenGL. Just the raw bytes would take ~480mb of disk space. Something like deflate could be used to make this significantly less, but the overhead would have to be smaller than IMGDecoder (which probably isn’t hard). For this to be feasible, the resulting temp files would have to be reasonably small since Android doesn’t have an abundance of storage. On Android I use a lower resolution, so I need only ~30 images instead of ~120.