From: mssmith@afterlife.ncsc.mil (M. Scott Smith)
Newsgroups: comp.sys.mac.programmer
Subject: Animating sprites ?: restoring bkground
Date: 22 Nov 92 18:56:48 GMT
Organization: The Great Beyond

Hello..

   I know I've asked lots of questions about animating on the Mac in the
past, but I'm not out of questions yet.  :)

   I still am struggling with ways to "restore" the background behind a
sprite once a sprite moves on.

   For example, in games like Lemmings, I'll call each of the Lemmings
a "sprite" (for lack of better word).  Now, say a Lemming is walking past
a tree which is in the background.  As the Lemming walks past it, he doesn't
leave a trail of black behind; the tree is "restored".

   I know how to make parts of the tree appear through the Lemming, by using
masking or transparent copy modes, etc.

   But now I'm trying to deal with the issue of restoring the background of
an area that a sprite was on top of, once the sprite has moved on.

These are some ways I've considered:

- If I have a little man walking to the right, then I could include draw
a black border around the man (at least on the left, if walking right) so
that he would automatically erase his old position as he moves along.
Hmm.  Actually, I guess this is a separate problem I'm having, which
involves erasing the old position.  I'm still trying to find quick ways to
do that.  But it's related to the background question.  (I've found that
if I include a black border, then I can't take advantage of the transparent
copy mode or other methods of letting the background "seep" through; in
addition, adding that border takes up more bytes, which may or may not
be something worth worrying about.

- Do a CopyBits of the rectangular area that will be affected when a sprite
moves into it.  Draw the sprite in the area.  Then slap that rectangle of
the background back on the screen to restore it (and, I guess, erase the
sprite), then keep a copy of the next rectangle that will be affected, etc.
I haven't tried this yet, but it seems this might be slow and possibly
result in flickering.  After all, you're working with rectangles and will
most likely be copying bits that wouldn't need restoring anyway.

I guess that last method is the way I have a feeling it might be done.
But it doesn't seem right.

Am I missing something pretty obvious with this?  I see the animation in
Lemmings and other games and when a sprite walks past a background, it's
pretty fluid in restoring it.  It looks like "real life", basically.

Actually, I have tried something similar to the last method once, and the
results were OK, I guess.  I have a sprite (about the size of a Lemming),
and it walks past a ladder.  Once it passes the ladder, I just re-draw the
sprite of the ladder on the screen, and that looked fine.  But with that
program, I purposely made the sprites make 15-pixel jumps to save time
on animation.  (I wasn't trying to do smooth animation, just trying to
test out an idea for a game.)  And the ladder was less than 15-pixels wide,
so the animated sprite was only over it once in its animation; now that
I'm trying to refine the animation, the sprite would probably be over
it a couple of times before it moved on, and I'm worried the same method
might make flicker.

Sorry for my unorganized thoughts.  Any help would be appreciated.  In fact,
I wouldn't be anywhere so far if it wasn't for all the great help I've
received from the net.

(I guess to sum it up, I have two main questions: what's the best way of
restoring a background as a sprite animates across it, and also what's the
best way of "erasing" a sprite as it moves.)

Thanks in advance!

M. Scott Smith
  (mssmith@afterlife.ncsc.mil || umsmith@mcs.drexel.edu)