Game Development Reference
In-Depth Information
As you can see from this class, we have simply filled in values for all of the variables in the
Level
base class (notice that
Level1
extends
level
). We have also copied the 2D array data from the
level1_back.as
file that we exported from Mappy and assigned it to the
backGroundMap
array. We
did a similar operation with the
level1_sprites.as
file we exported from Mappy. For this data, we
assigned it to the
spriteMap
array variable.
Updating the New GameDemo.as file
Now that we have an actual tile sheet created, a
Library
to put it in, a class to hold its instance,
and level data to draw from, we can start to look at actually putting it on the screen. To do this, we
are going to go back to the
GameDemo.as
file and add some code to paint the background with the
tiles from the
Level1.as
file
Here are the three main steps we must accomplish in the following code to finally paint out
background on the screen:
1.
We must parse the level data and put it into a 2D array.
2.
We must paint the 2D array of background tiles to our out output display canvas.
3.
We must add the canvas to the stage.
The class imports
Replace the entire class import section in
GameDemo.as
with this set of code:
package com.efg.games.notanks
{
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData
import flash.geom.Rectangle;
import flash.geom.Point;
import com.efg.framework.TileSheet;
Notice that we have added a few new classes that will be needed for the blitting operations. The
geom
and
display
package classes will do the bulk of the work there. Also notice that we have
imported the
com.efg.framework.TileSheet
class we created earlier and saved into the
framework package structure.
The variable definitions
Replace the entire variable definition section from original
GameDemo.as
with the following:
public class GameDemo extends Sprite{
public static const TILE_WALL:int = 0;
public static const TILE_MOVE:int = 1
public static const SPRITE_PLAYER:int = 2;
public static const SPRITE_GOAL:int = 3;
public static const SPRITE_AMMO:int = 4;
public static const SPRITE_ENEMY:int = 5;
public static const SPRITE_EXPLODE:int = 6;
public static const SPRITE_MISSILE:int = 7;