Does someone of you know how to use/create animated sprites?
Could you please give me the link for a good beginner tutorial?
Thanks
Does someone of you know how to use/create animated sprites?
Could you please give me the link for a good beginner tutorial?
Thanks
What >I< usually do is have a counter. Either a global one, or
an object-specific one… depends on what I need.
(Is it just a shape that’s animating along with everything else
on the screen? Or does this shape change depending on other
factors?)
Using the ‘global animation’ counter example, here’s what I do.
int my_main_loop()
{
…
Uint16 frame_counter;
…
/* THUS BEGINS THE MAIN LOOP!!! */
do
{
/* Increment the global animation counter: */
frame_counter++;
/* ...handle incoming events (key, mouse, timers, etc.)... */
/* ...erase objects from the screen... */
/* ...move objects around; check for collision, regeneration, etc... */
/* Draw the objects! */
for (i = 0; i < NUMBER_OF_BAD_GUYS; i++)
{
if (bad_guy[i].alive == TRUE)
{
draw_shape(screen, /* Draw onto the screen surface (game window) */
bad_guy[i].x, /* At the bad guy's screen... */
bad_guy[i].y, /* ... coordinates */
img_bad_guy_shapes[frame_counter % 3]);
/* One of the three pictures of bad guy */
}
}
/* ... */
}
while (gameover == FALSE);
/* … */
}
So here, I have a theoretical function called “draw_shape”.
I send to it four things:
SDL_Surface * dest; <- onto what surface I’m drawing the shape
int x, y; <- x,y coordinates
SDL_Surface * src; <- what surface I’m copying from
In the code above, we assume that I have an array of bad guy shapes:
SDL_Surface * img_bad_guy_shapes[3];
and that, obviously, I have loaded the shapes into them.
For each frame of the game, the shape shown for all of the bad guys
alternates between these three images (1, 2, 3, 1, 2, 3, 1, 2, 3…)
That’s pretty basic, but is good for things like Space Invaders, or
to animate flames in the background somewhere.
Since I’m using a counter that just counts up forever, and then MOD (%) it,
I can use the counter for other sprites that have more shapes.
When the counter rolls over, things might animated slightly wrong
between one frame and another, once, but that’ll only happen occasionally.
If it’s a big deal, use separate counters for each ‘thing’ you want animated,
and then don’t use %, just roll the number over yourself:
bad_guy_frame++;
if (bad_guy_frame > 3)
bad_guy_frame = 0;
Hope this helps!
-bill!
bill at newbreedsoftware.com Got kids? Get Tux Paint!
http://newbreedsoftware.com/bill/ http://newbreedsoftware.com/tuxpaint/On Sat, Dec 06, 2003 at 12:50:22PM +0100, Kroedler wrote:
Does someone of you know how to use/create animated sprites?
Could you please give me the link for a good beginner tutorial?
Hi!
Check this:
http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/gfxsdl/index
That is all you need
Good luck!
Kroedler wrote:> Does someone of you know how to use/create animated sprites?
Could you please give me the link for a good beginner tutorial?
Thanks
Thank you for your help Bill!
Your source code works really good…
I’m coding an 2d Adventure(Monkey Island style)atm.
Bye
Kroedler