Game Development Reference
In-Depth Information
The
tileRect
and
tilePoint
instances will be used to blit each tile to the screen in the
right place inside of our render loop. The
tileRect
will always be a 32
32 square, but
the
tilePoint
x and y values will change based on the location of the tile (column and
row) in the screen buffer.
The
canvasBitmap
will be added to the Game's display list and will contain the 384
384
canvasBitmapdata
of our main output canvas. The
camera.bufferBitmapData
will be
painted into this on each frame tick.
The
backgroundBitmap
will be added to the display list behind the
canvasBitmap
. It will
contain the
backgroundBitmapData
that in turn will be filled with the 12
12 background
tiles specified in the level data XML.
The
backgroundBitmap
and the
canvasBitmap
are added to the display list.
Our
lookAheadPoints
list is set to contain three
LookAheadPoint
instances. All three are
added to the display list, but you will want to comment out these three lines when your
testing is complete. This is created using the ActionScript 3.0 (Flash Player 10 and
above only)
Vector
class. The
Vector
class allows the developer to create an optimized
array with a predefined size and only a single data type. Flash can manage memory
better and is much faster at accessing data that is organized in this manner. We have
used it here as an example. If you are using Flash Player 9, it can be swapped out with
an
Array
class instance.
The newGame function
This is the full code for the
newGame
function:
override public function newGame():void {
switchSystemState( STATE_SYSTEM_GAMEPLAY );
initTileSheetData();
player = new CarBlitSprite(tileSheet, playerFrameList, 0);
addChild(player);
level = 0;
score = 0;
gameOver = false;
dispatchEvent(new CustomEventScoreBoardUpdate(CustomEventScoreBoardUpdate.
UPDATE_TEXT, Main.SCORE_BOARD_SCORE, String(score)));
dispatchEvent(new CustomEventScoreBoardUpdate(CustomEventScoreBoardUpdate.
UPDATE_TEXT,Main.SCORE_BOARD_TIME_LEFT,"00"));
dispatchEvent(new CustomEventScoreBoardUpdate(CustomEventScoreBoardUpdate.
UPDATE_TEXT,Main.SCORE_BOARD_HEARTS,String(0)));
//key listeners
if (!keyListenersInit) {
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownListener);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpListener);