Working with a collection of images... advice?

In a JAR i have images that are a collection of smaller images. For example vehicles contains 20x20 images like “tank facing forward”, “facing backward”, “car forward”, etc.

I’m constantly accessing these and displaying them. I’d appreciate feedback on good ways to use/manage this collection.

Like, would it be better to separate them into files? Is there better code than loading the whole image then only using a few of the images? Faster methods? Any sample code out there?

Thanks

Faster how? Faster load time? Faster image drawing speed? Or faster to work with when editing / drawing the images while developing?

Why exactly do you have multiple images in one big image in the first place? What does this gain you? What’s wrong with the current method?

Yeah, you want to make a sprite atlas. Google it.

At the moment, it takes a long time to load the whole image. Once it’s in memory, it’s fast and easy to grab each image i need. This is okay, but takes a moderate of memory and load time. I just thought there might be a better way that others are dealing with thousands of source images.

The only thing i gain is not having a jar filled with too many images. I really don’t gain much. What’s the current method?

:wink:

http://www.lmgtfy.com/?q=what+is+a+texture+atlas

Basically you make a really big image, pack a bunch of small images in it, and then store the image location data in a text file or XML file or something. Then you load that image once and store it in memory. Instead of drawing the whole thing, you just draw the portion you want. This is what professional video games do.

Thanks for the help! Knowing the term (texture atlas/sprite atlas) helped me to find some examples and explanations. Like: http://rbwhitaker.wikidot.com/texture-atlases-1

I still have the issue with my map tile set of over 1000 images being a large file to load or a long list of images in the JAR. I think i’ll play around with converting BufferedImages to byte arrays and storing the images to a file.

Storing it as an actual image will almost always be cheapest because they’ve got smart compression algorithms in there. I recommend PNG.

If you’ve got a lot of assets, make big atlases and a lot of them. Then just use them intelligently (don’t swap between them more than you need to). There’s really nothing else you can do.

Thank you… makes allot of sense to me. Glad i asked :slight_smile:

And and use a utility like PNGCrush to really bring them down to size.