Animation of a sprite

Started by
1 comment, last by zeroshot 22 years, 2 months ago
OK i have not got to the stage where i want to load a bitmap file into a surface in which the bitmap file comprises of a number of frames of a sprite animation say a man walking like a flipbook what is the best way to do this im using the RECT struct to tell DDraw which part of the image to blit etc ie lpSprite = DDLoadBitmap( lpDD , "sprites.bmp" , 0 , 0); RECT rect ; rect.top = 0; rect.left = 0; rect.right = 40 ; // rect.bottom = 40 lpBack->BltFast( 100, 100 , lpSprite , &rect , DDBLTFAST_WAIT ); lpPrimary->Flip( 0 , DDFLIP_WAIT ); thats loads the 1st image in the file ne ideas lads pritty plz Ta in advance
Advertisement
Make all the animation frames the same size and load them onto a surface. Then keep the location of the rects in a variable and then change the variable according to what frame you want to display at that time.

Look at the Donuts sample with the SDK (I''m assuming you''re not using DX8 since you''re talking about DDraw).
Hi there, hopefully, this will help u.

Say u have a character who has 6 different cells of animation in your template, like this:

-----------------------
| | |
| | |
-----------------------
| | |
| | |
-----------------------

Which means that u have 3 cells in every row. Now,cell 1 becomes FRAME 0, cell 2 becomes FRAME 1, cell 3 becomes FRAME 2, and so on. Now all u have to do is set up a destination rect, which is very simple, and a source rect. Source rect is a bit tricky. U have to do the following if u want your program to extract cells correctly.
(Assume src_rect is your source rectangle, and that every cell is 64*64)

src_rect.left = 64 * (FRAME % 3);
src_rect.top = 64 * (FRAME / 3);
src_rect.bottom = src_rect.top + 64;
src_rect.right = src_rect.left + 64;

Thats it. You''ll probably make some sort of "for" statement or increment so that your FRAME value is initially at 0, and then it increments by one unit until it reaches the total number of frames which in this case is 5 (One minus the total number of cells).

If u are new to programming and have trouble understanding how modulus operators work, then just put the above code in the console application and observe what happens. Modulus basically just takes the remainder of a number. If u wanna implement a really good sprite engine, then try using linked lists, since it''s one of the best methods out there. But then again, u can always just get away with a little for loop and a bunch of arrays.

I hope this helped u, cya

This topic is closed to new replies.

Advertisement