Game Development Reference
In-Depth Information
for (var rowCtr:int = 0; rowCtr < mapRowCount; rowCtr++) {
for (var colCtr:int = 0; colCtr < mapColumnCount; colCtr++) {
tileNum = spriteMap[rowCtr][colCtr];
switch(tileSheetData[tileNum]) {
case SPRITE_PLAYER:
player.animationLoop = false;
playerStartRow= rowCtr;
playerStartCol= colCtr;
player.currRow = rowCtr;
player.currCol = colCtr;
player.currentDirection = MOVE_STOP;
break;
}
}
}
}
This function is used to parse the 2D array of data in the levelData.spriteMap variable. As you
might recall, this variable was assigned readBackGroundData function in the original GameDemo.as
file. Here is a breakdown of what is happening in this function.
We will loop through this data using a nested loop structure. A nested loop structure contains an
outer loop that will iterate though the rows in our sprite data, and inside each row, we will iterate
through each column. This inside loop through the column data for each row is the nested loop .
1.
We create a local variable called tileNum . This will hold the current tile id for the
[row][column] on our sprite layer when we iterate through the level sprite data.
2.
We assign the spriteMap class variable the value of the levelData.spriteMap
contents.
3.
We start our outer loop using the local rowCtr variable (starting at 0 ) while it is less
than the mapRowCount amount ( 15 ).
4.
The inner, or nested, loop through each column in the current row begins by using the
colCtr variable to start at 0 and loop through all of the columns while it is less than
mapColumnCount ( 20 ).
5.
The current tileNum is the value in the array at [rowCtr][colCtr] .
6.
That tileNum is plugged into the tileSheetData single dimensional array to find the
type of sprite that is in that location. If you recall, the i nitTileSheetData function
parsed the data in the TileSheeDataXML.as file as assigned a constant to the value of
each sprite in the t ileSheetData array.
7.
We start a switch:case statement based on the constant.
8. The player variable is assigned with its starting values.
The player begins with its animationLoop variable set to false . The tank is stopped
( player.currDir=MOVE_STOP ) when the level begins. We don't want the tank treads to animate
while the tank is stopped, so we set this to false .
Search WWH ::




Custom Search