[A83] Re: Tilemap


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

[A83] Re: Tilemap




The method that I came up with for Zelda 86, that other people copied later
(so it must be good, right?), was to use change lists.  To make it easier to
explain, I'll paste the change list (view in a fixed width font):

; (old, new)
AnimateMapList:
 .db 164,165, 165,166, 166,164                  ; waterfall
 .db  81,167, 167,81                            ; torch
 .db 129,132, 132,129                           ; water
 .db 130,131, 131,130                           ; waterfall splash
 .db 104,176, 176,104                           ; person
 .db 168,169, 169,170, 170,171, 171,168         ; kid w/ bouncing ball
 .db 172,173, 173,174, 174,175, 175,172         ; teleporter
 .db 177,178, 178,179, 179,180, 180,177         ; guy w/ shovel
AnimateMapListSize = ($ - AnimateMapList) / 2

You'll notice that the numbers are in pairs.  As the comment indicates, the
first number is the old tile number, and the second number is the new tile
number.  To animate the map, you run through the change list for each tile
on the map.  If the tile matches an old number, you replace it with the new
number.  Only one replace is done per tile, so as soon as a replace is done,
skip to the next map tile.

This technique can work very well is some circumstances.  Zelda uses a
tripple buffering system.  The map is drawn to a buffer.  Each frame, the
map buffer is copied to a working buffer, the virtual screen, sprites are
drawn, and finally the buffer is copied to the screen buffer.  The advantage
here is that you never have to worry about erasing sprites.  You just draw
everything that should be visible each frame.  This makes the code a lot
simpler.  It's also faster because you don't have to actually redraw the map
each frame.  In Zelda, the map is only redrawn once every eight frames.
This gives nice looking animation, but of course, this will be different
depending on a lot of different factors.  The code in Zelda to draw the map
is not incredibly efficient, but that doesn't really matter in it's case.
Before I added map animation, the map only needed to be drawn once, before
the screen was displayed.  Zelda 86 is in the style of the original NES
version, or the Game Boy version, where it displays a single screen at once.
I remember trying to redraw the map every frame, and it was too slow.  This
could have been fixed by making the map rendering routine more efficient,
but that wasn't necessary.  On frames when the map is not draw, several
halts are used for a delay, to give a consistent speed to the engine.

If you have a side scroller where you are using traditional Sqrxz style
scrolling, then this won't work, because you are never redrawing the entire
map.  You could use sprite routines and actually draw the map tiles that
change, but if many tiles change, this could easily be too slow.  There
really isn't a good way to do animated map tiles for this style of engine,
simply because drawing lots of arbitrary sprites to random locations on the
screen every frame will be too slow.

For a scroller to do animated map tiles, the only real solution is to redraw
the map every frame.  This is quite possible.  Both Kirk Meyer's Commander
Keen for the 86 and Hideaki Omuro's (crashman) TileMap routine for the 82
use this method.  With these types of engines, you can use any method you
like to change the map tiles.  Changing them will cause the new map tile to
be drawn on the next frame, so you can easily have an animated map tile
change every frame.

Change lists are powerful, but can be slow, especially if they are large.
Another method that Kirk's Commander Keen uses (I believe) is to use
different ranges of the tileset every frame.  For example, if you want four
different animation frames, then you can have 64 different map tiles.  The
map will only contain values of 0-63.  On the first frame, tile 0 is drawn
as tile 0.  On the second frame, it is drawn as 64, on the third frame 128,
and on the fourth frame 192.  This requires you to have a lot more tiles
than you probably need, and substantially limits the number of unique tiles.
You can use tricks to work around these limits.

There are probably other methods of doing tilemap animation, but these are
the ones that are the most obvious.  I don't remember seeing anything being
used that is substantially different, but if you come up with something, I'd
be interested in hearing about it.

> I've been wondering what the easiest (and fastest) way to do this was as
> well.
> >
> >Also could anyone tell me how to animate tiles in a tilemap with some
> >example code, Thanks






References: