sprite animation

Started by
10 comments, last by CC Ricers 19 years, 9 months ago
Quote:Original post by Anonymous Poster
yeah i know how to do like walking or somthing similar, i was wondering about a full blown, say, attack animation, where there are up to 20 frames. could i use the SDL_GetTicks() and just have the animations in the array blit in the order of the Tick and also write a simple calculation for xy positioning?

if that is the way to do it, is that the most efficient way to?

thanks again!


Better yet, loading one image as a sprite set instead of many little ones. Then just look up the coordinates of each sprite in your favorite graphics editing program and note them down. You can then 'plug' these numbers in the appropriate (int) values for the blit_img function. You should probably store these numbers as another vector or array.


Advertisement
So suppose I have a sprite set bitmap where all the sprites are in a row, and each is 20-25 pixels wide. I would want the portion in view to change in order to create the illusion of motion (think of a zoetrope).

int i=0;int xpos[5] {0, 20, 45, 65, 90};// x, y = where the sprite on the screen is at the moment// as i changes, a different image would be seen from the sprite set    while (key_is_pressed) {        Blit_img(sprite, x, y, 20, 30, (int)xpos, 0);        i++;         if (i >= 5) {i = 0;} // 33 milliseconds for 30 fps        SDL_Delay(33);    }


I just got this out of my head since I can't test it right now. But if someone can tell me if this will work on their programs let me know. Also tell me if I'm missing something.

New game in progress: Project SeedWorld

My development blog: Electronic Meteor

This topic is closed to new replies.

Advertisement