[SDL] Multiple Images in one file

Paul Lowe spazz at ulink.net
Wed Aug 25 01:14:03 PDT 1999



ben.campbell at cyberlife.co.uk wrote:

> > >d00d, write your own animation format. It's easy as hell.
> > Just write out the
> > >surface->pixels to a file for each frame, and then load all
> > of it into memory
> > >with the same specs etc, it's easy.
> >
> > Better to stick with some standard so people can mess around with the
> > artwork after the fact (if it's open source). Nice to have
> > open data files
> > along with the open source code.
>
> Also, it means an easier change to another format if the need arises.
> Hypothetical example: maybe you'd like a lean version with a quick download
> time - just convert your graphics to jpeg and rewrite your loading routine.
>
> On the other hand, there's a lot to be said for making up a simple
> multi-image format when you're dealing with many many little sprite
> images...
>
> Most important thing - keep the actual source of your imagery (eg bmp, png,
> roll-your-own-custom-format, algorithmically generated, whatever)
> independant from how it is used, so if you change your mind later on it's
> not such a big deal.

JPEG sux. It's lossy. Just do this:

Use PPM, or TIFF or something non-lossy, I dunno if compression is something
you need or not. One thing you can do is draw rectangles containing all the
frames of animation into the image like this:

(actual image)

------------------------
|   1   |   2   |   3   |   4   |
------------------------

Then load the big image, and extract those rectangles into whatever data
structure etc you use to natively reference the frames in your sprite, then
free the image.


What I do is:

make a file for each frame of each sprite:

play_walk_left_1.ppm
play_walk_left_2.ppm

explosion_1.ppm
explosion_2.ppm
explosion_3.ppm

etc.

Then load them, this way they're easy to access, and I can edit any frame at my
conveinience.


Paul Lowe
spazz at ulink.net




More information about the SDL mailing list