Mail Archives: djgpp/1999/03/11/17:05:58
I (actually Andre Lamothe) use a struct for each sprite. It contains x
and y position, oldx and oldy for erasing, a current frame counter,
the number of frames, a frame delay, a frame delay increment, and an
array of pointers to bitmaps.
How it works is, on every game loop you increment the frame delay
increment. When it reaches the value set in frame delay, you reset it,
and it's time to change to the next frame. So your animation can be
one frame every 4 game loops, say.
When it's time to change to the next frame, we add to the frame
counter. This gets modulated by the maximum number of frames, so it
loops round.
Then in your sprite draw routine (mine, and Andre's, just takes one
argument, a pointer to the sprite you want to draw), you just draw
whatever bitmap
sprite.frames[sprite.currentframe]
is pointing to.
How I do it, you have to decide the absolute maximum number of frames
any sprite can have at compile-time, the array of pointers to the
bitmaps is a set size, I think my sprite.frames[16] is set as 16
pointers, but it could be dynamic if you could be bothered coding it,
it's only 60 bytes at most wasted per sprite so it's no big deal.
------------------------------------------------------------------------
The person who said he was a crap presenter knows nothing because compared
to the outwardly camp stuart miles, speech impediment Katy Hill and nothing
upstairs Konnie Huq, he was a true professional. Heh heh heh.
- Raw text -