Game Development Reference
In-Depth Information
The
blitPoint
is used in
copyPixels
blitting operations to specify the top-left (x,y) position to start
the painting of a tile sheet tile onto the
canvasBitmap
. The
tileBlitRectangle
will be used to
specify the top-left (x,y) position on the tile sheet to start copying the 32
32-pixel
Rectangle
.
This
Rectangle
will be placed on the
canvasBitmap
at the
blitPoint
. You have seen the
tileSheet
variable before; we instantiate the
tileSheet
by passing it an instance of the library
item
TankSheetPng
along with
width
and
height
for our tile.
The constructor
The new constructor adds in code to call some new functions.
public function GameDemo() {
initTileSheetData();
readBackGroundData();
readSpriteData();
drawLevelBackGround();
addChild(canvasBitmap);
}
First, we will read the background data in from the
Level
instance. Next, we will call a stub
version of the
readSpriteData
function. We will not be implementing this function in this chapter,
but we want to make sure we point out that the sprite data is not read in when we read in the
background data. We will next draw our background to the
canvasBitmapData
with the
drawLevelBackGround
function and finally add the
canvasBitmap
to the stage.
The readBackGroundData function
The
readBackGroundData
function is completely new. We will use it to read through our level data
and create the 2D
levelTileMap
array.
private function readBackGroundData():void {
levelTileMap = [];
levelData = levels[level];
levelTileMap = levelData.backGroundMap;
}
The
readBackGroundData
function is very simple. In Chapter 7, we will add code to read more of
the level-specific variables from the
Level
class instance, but for now, we will keep it very simple.
We first initialize the
levelTileMap
array by assigning it the shortcut
[]
value. Next, we place a
reference to the current
Level
object into the
levelData
Level
class instance. Finally, we simply
assign the
levelTileMap
array to reference the
levelData.backGroundMap
array. That is all we
need to do to start using the level data.
The readSpriteData function
The
readSpriteData
function is only a stub placeholder that we will fill in when we get to Chapter 7.
private function readSpriteData():void {
//place holder for reading sprite data and placing sprites on the screen
}