on 11/12/01 11:56 PM, Bryan Arant at bryan at barant.com wrote:
Heya everyone, got a new problem
In SDL, how do I go about doing animations? I know that I can obviously load
5 different files for 5 animations of one object, but that gets to be a pain
in the butt, especially after you have 5 animations for walking, jumping,
crouching, shooting, etc… Too many files.
How do I create just 1 .bmp file with ALL the animations in it? Split up in
to blocks of course, then blit according to the frame I am on?
This is how I go about it…
Make one bmp that is a multiple of your sprite’s size. Say your sprite is
50x50 pixels. make a bmp that’s 50 by 400 or 200 by 800, whatever, then you
can divide that file into 50 x 50 rows and/or columns, each being a frame of
animation.
I usually add in an additional pixel of width/height between each region so
I can draw in borders to help me know where each region ends when I’m
drawing the sprites. You have to account for this when blitting.
then when you go to blit, grab one region out of the file with your
SDL_Rect.
SDL_Surface* sprite = SDL_LoadBMP("./sprite.bmp");
//etc
int column, frame_in_column;
//determine these values based on what’s going on in the game
SDL_Rect src, dest;
src.x = 50 * column;
src.y = 50 * frame_in_column;
src.w = 50;
src.h = 50;
dest.x = //somewhere on the screen
dest.y = //somewhere on the screen
dest.w = 50;
dest.h = 50;
SDL_BlitSurface(sprite, &src, screen, &dest);
so if you want the frame that is 2 over and 4 down, column would equal 1 and
frame_in_column would equal 3;
Matt_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com