Re: A89: Help! Animation In C!


[Prev][Next][Index][Thread]

Re: A89: Help! Animation In C!




In a message dated 9/6/00 8:17:38 PM Mountain Daylight Time, 
fuzmeister@juno.com writes:

> I was wondering if someone could tell me or show me how to do
>  a simple routine for doing say two or three frame animation in C
>  using 32x32 grayscale sprites?
>  
>  I'd like to make a good game in C one of these days and that's kind
>  of neccessary for making a decent game graphics wise.

I know David Phillips related me a while back a good implementation for 
animation of sprites (both moving and static).  You basically just create a 
list of the sprite indexes of the animation frames and keep an index to the 
list, updating it every frame (wrapping when necessary), and drawing the 
sprite for each object based on the the sprite index the list index points 
to...sounds complicated, maybe, so an example might help (I'm just gonna use 
TASM Z80 syntax since I'm not quite comfortable with a68k's...).  If you want 
an object, say an enemy, to animate through frames 45, 46, and 47, you'd just 
have a list like:

.db 3, 45, 46, 47

(It'd probably be < dc.b 3, 45, 46, 47> in a68k syntax...?)

Then just keep a byte in RAM that indexes this list.  At each frame, simply 
draw the sprite index the list index points to (to reiterate...) and increase 
the list index until it reaches the maximum value (as indicated by the first 
byte in the list).  Depending on how you'd wanna implement it, you could also 
reserve a "sprite index" that doesn't exist, such as $FF, that would signal 
the list index to go back to the beginning of the animation list (perhaps the 
byte after the first $FF before?).  For example, you could do several 
animation lists this way:

.db $FF
MainCharacter:
.db 1,2,3,4,5,$FF
Enemy1:
.db 56,78,34,$FF
; .
; .
; .

Also notice that this allows the sprites in your sprite table to really be in 
any order...

Just one suggestion, there are, of course, plenty of other ways you can 
animate sprites.

JayEll