Game Development Reference
In-Depth Information
XML data is pretty easy to traverse in AS3. We can simply loop through all of the nodes in the
XML data that contain tile data as if they are part of an array. We first find the number of tiles in
the data like this:
var numTiles:int = tileXML.tile.length();
Pretty simple, right? Next, we just loop though the XML as if it was an array and check out the
attribute content of each <tile></tile> node in the XML data. Our first check is to see if the tile
is walkable or nonwalkable . If either of those is the value of the type attribute, the corresponding
constant is stored in our local numberToPush variable. The value will either be TILE_WALL or
TILE_MOVE . If the tile type is sprite , we have to do a second check using the name of the tile.
Depending on the name value, our switch:case statement will both assign values to our tile
arrays (described in the previous section “The constants”), and assign the corresponding
constant to the numberToPush variable. After a number constant has been assigned to the tile and
any associated arrays have been updated, we finally add the constant value to the tileSheetData
array.
You have seen the final two lines before. Those are for the explode arrays. We discussed those
in detail in the previous section.
Testing it out
In either the Flash IDE or Flash Develop, you can test out this file with no changes. For Flash
Develop, remember to set GameDemo.as the always-compile file. In The Flash IDE, make sure
GameDemo is the document class of the game_demo.fla , and test the movie. You should see the
output shown in Figure 6-11 in the trace window (unless you have modified the tile sheet for your
own purpose).
Figure 6-11. The trace output for this demonstration publish or build
This output shows the lengths of the arrays we created after the initTileSheetData function was
called. The first trace shows the length of the tileSheetData array ( 32 ). Next, we see the number
of tiles for both the playerFrames array and enemyFrames array ( 8 ). The missileTiles array only
contains a single tile id , while the explodeSmallTiles and the explodeLargeTiles arrays contain
3 and 5 respectively.
Displaying the level data on the screen
The next task we are going to tackle is reading the level data and displaying it on the game
screen. This is going to make use some tile sheet blitting techniques that we will discuss shortly
in the section called “Tile sheet blitting and sprites.” We will again be using the GameDemo.as file
and updating it to include the new code. We will require some slight differences between the Flex
Search WWH ::




Custom Search