Download Sample Chapters from Book.

Transcript
© 2009 NURVE NETWORKS LLC “Inside the XGS PIC 16-Bit”
Figure 15.19 – Copying the background tile map into a working tile map, so you can overwrite it.
This is fine, but you double the amount of tile map memory you need. However, many times this is much better than
trying to remember every tile that you draw onto in your animation loop. For example, coming back to the previous
Atari “Pitfall” example, say you want to move the scorpion across the screen as shown in Figure 15.20.
Figure 15.20 – Tile animating the “Pitfall” scorpion.
The left image shows the tile map we want to move the scorpion in (the top scorpion) and the tile bitmaps again. As
you can see, there are 2 frames of animation in the tile map (for right/left and the different potential background
colors), but as we move the scorpion and animate it, we are going to either leave a trail of destruction or incorrect
tiles. That is as you move the scorpion from left to right, you must replace what tile was under it, therefore you either
need to keep track of it, or you need to use the above aforementioned “working copy” of the tile map. However, for
the fun of it let’s look at what the code might look like to just remember what was under the scorpion and replace that
every time we move it. Let’s assume that the scorpion tile bitmap frames are numbered 5,6 that we want to animate
(right walk as shown in the figure if you count tile bitmaps from left to right, top to bottom starting from 0), and we
aren’t going to worry about timing issues, borders, collision, just the animation and the background tile copying. The
code would look something like this:
49