Game Development Reference
In-Depth Information
public var startX:Number;
public var startY:Number;
public var nextX:Number;
public var nextY:Number;
//the buffer is 1 tile longer and higher than the camera
//well first copy all of the tiles to the buffer
//then copy just the portion we need to the camera
//buffer
public var bufferBD:BitmapData;
public var bufferWidth:int;
public var bufferHeight:int;
public var bufferRect:Rectangle;
public var bufferPoint:Point;
public function Camera2D() {
}
}
}
As we described earlier, the Camera2D class is simply a BitmapData canvas that will be used to
hold the current set of tile data before it is copied to the output window. The x and y coordinates
indicate where on the 50
32 pixels (1,600 pixels in each direction) files to start
the copy of tiles to the buffer. The buffer actually contains enough space to hold 13 tiles. So, for
the x dimension, the buffer will contain 416 pixels (13
50 grid of 32
32 = 416), and the same in the y
direction. When the buffer is copied to the final output canvas, we move over to the actual start
pixels in the x and y dimensions on the buffer and only copy 384
384 pixels.
Double (and triple) buffering
The Camera2D class also acts like a double buffer for the game display. You will notice in the
game code that we copy all of the tiles to the screen each frame. By using the buffer, we also
eliminate any chance of screen flicker because the draw operation of each tile occurs off screen.
The loop through the tiles and the individual copyPixel operations for all 144 tiles 40 times a
second takes some processor power. We do this off screen to reduce the processor needed and
to eliminate the player from seeing any of the draw in sometimes associated with scrolling. If you
have seen the crawling up or down the screen on the edge tiles on some scrolling games, you
know what we am talking about here.
When we get to the game code, you will see that we will also use another type of buffer for our
display. You have seen this in previous chapters in the topic. Before we copy the buffer to the
canvas, we will call the canvas lock method. This prevents the output Bitmap instance that holds
the canvas from being updated until the entire copy operation is complete. So, to create our triple
buffer we first copy all of the tiles to the off screen buffer in the Camer2D class, and then we lock
the canvas and copy the needed pixels from the camera buffer to the output canvas off screen.
Finally, we place the pixels on the screen with the canvasBD.unlock .
Creating the classes specific to Drive She Said
The rest of the classes for the game are specific to Drive She Said and will be created inside the
project folder along with the Main.as and Library.as classes.
Search WWH ::




Custom Search