views:

115

answers:

3

Maybe not really big, but a hundred frames or something. Is the only way to load it in by making an array and loading each image individually?

load_image() is a function I made which loads the images and converts their BPP.

expl[0] = load_image( "explode1.gif" );
expl[1] = load_image( "explode2.gif" );
expl[2] = load_image( "explode3.gif" );
expl[3] = load_image( "explode4.gif" );
...
expl[99] = load_image( "explode100.gif" );

Seems like their should be a better way.. at least I hope.

+1  A: 

maybe simplify your loading with a utility function that builds a filename for each iteration of a loop:

LoadAnimation(char* isFileBase, int numFrames)
{
    char szFileName[255];
    for(int i = 0; i < numFrames; i++)
    {
       // append the frame number and .gif to the file base to get the filename
       sprintf(szFileName, "%s%d.gif", isFileBase, i);
       expl[i] = load_image(szFileName);
    }
}
Andrew Garrison
Thanks for the code, I'll probably use this for this first program I'm making.
Justen
+1  A: 

A common technique is spritesheets, in which a single, large image is divided into a grid of cells, with each cell containing one frame of an animation. Often, all animation frames for any game entity are placed on a single, sometimes huge, sprite sheet.

TokenMacGuy
This is probably the best way in the long run, if the amount of frames is quite large (say over, 15)
Skurmedel
I was considering sprites, but I wasn't sure if they were still the best way since I would have to iterate through and cut out SDL_Surface. So this is still a good way of doing something that has.. let's say 50 frames of animation?
Justen
Fundamentally, something is iterating over the data in the animation. The SDL_BlitSurface function makes this very efficient. I've seen this technique used to blit sprites with more than 200 frames. There's no particular reason you couldn't use even more.
TokenMacGuy
+1  A: 

Instead of loading as a grid, stack all the frames in one vertical strip (same image). Then you only need to know how many rows per frame and you can set a pointer to the frame row offset. You end up still having contiguous scan lines that can be displayed directly or trivially chewed off into separate images.