Why do people put sprites in one file?


Richard Marks:
I had this guy ask this question today, and I felt I should write this here in addition to answering him where he asked.


Original post by some-idiot
Why do people put lots or even all of their game sprites in one image file? I guess it was some sort of optimisation year ago, but is it wise to do it know too? Code would be much clearer if every frame of animation is a separate image file.

If you aren't talking about for 3D accelerated games as the other people assumed...

Lets say for example you were making an RTS game.
You are likely to have several thousand frames of animation.
Like perhaps each unit has 16 directions of movement, and 4 frames of animation for each of 10 actions.

That would be 640 total frames of animation for each unit.
Now, lets say that you have 10 units in 4 categories each.

If you wanted to animate your user interface icons and the environment tiles (which no really well made RTS doesn't do this) that is going to really increase the number of images that your game uses.

So lets cap the number of icons to 20 with 3 state images. Unselected, Selected, and MouseHover.

I'll say that there are 16 animated environment tiles with 3 frames of animation each.
And another 512 non animated environment tiles.

So now we have a grand total of 26,220 images!

And that is really being "simple" with the design.

So you would rather have 26,220 image files littering your project's directory, rather than four?

1 for the units
1 for the non animated environment tiles
1 for the animated environment tiles
1 for the user interface icons

Hmm.. 4 files versus 26,220 files..

Sorry, I vote for packing as many images into a single image as I can.

A random note is the overhead for each image file (It depends on the format but at least width and height integers, PNG overhead is 63 bytes), when you combine your images into single files you are saving a lot of space!

26,220 * 63 = 1.65 megabytes. Or just .24kb for 4 images. (Not including the actual image size for either, this is assuming 1 pixel ;) ) When you are working with a huge number of images this can save a considerable amount of space.

Another factor is the file system / explorer you are using, windows explorer tends to die if you attempt to browse a folder with 100,000+ images, while a few of the same size will work fine.


Richard Marks:
You are very much correct there Josh.

There is also a limit to the number of files per directory that you are allowed depending on the OS.

Also, if you do not have enough RAM for your system to create the thumbnails .. your computer will lock up if you open the directory.

Then of course there is the HUGE difference between file formats. Look at a 1024x1024 24-bit BMP file size and compare it to a 1024x1024 24-bit PNG file size... the PNG is more than 90% :o smaller in my tests.


[0] Message Index