Game Development Reference
In-Depth Information
The Camera
The camera is just a set of variables that represent a subset of the world tiles using x and y
values to indicate the start point for the current display.
The Buffer
The buffer is a BitmapData canvas that is 13 tiles wide and 13 tiles high (one extra in each
direction). Because the player's car moves smoothly about the world, we cannot simply copy
from an array of 12
12 exact tiles to the output canvas without this buffer. We know the start tile,
but we don't know how far to the right or down the start tile needs to offset before copying pixels.
For this reason, we need a thirteenth tile row and column. This 13
13 grid of 32
32 pixels is
copied to the buffer.
The Output Canvas
The output canvas is 12
384 dimensions). Using an offset from
the top, left-hand corner, the output canvas copies from the buffer in one operation. This is where
the thirteenth row and column in the buffer come into play. Since we moved right and down in the
first tile to start our copy, the only way to display 384
12 tiles (32
32 tiles = 384
384 pixels is to copy from the thirteenth
tile in each direction. Take a look at Figure 10-2 for an example.
Figure 10-2. The buffer bitmap data
Figure 10-2 shows the contents for the buffer canvas for this example game output screen. As the
player car moves from left to right, we must scroll the top left start point of our buffer. As you can
see, the buffer contains 13 rows and 13 columns of bitmap data Let's say, for example, that the
actual camera is not on these exact tile boundaries, but starts at 10x and 12y of the first tile.
Search WWH ::




Custom Search