Game Development Reference
In-Depth Information
throw new ArgumentError( " Asset Class " +assetName+ " cannot
be found in loaded asset files. " );
}
//END ASSET MANAGEMENT
Once all the assets are loaded successfully, the level is ready to be
created through createLevel . To link up the classes referenced in the
XML, there is one helper function called getAssetClass that accepts a
class name as a string. It looks up the class definition in the common
asset ApplicationDomain and either returns it as a Class object or
displays an error if the asset does not exist.
//BEGIN LEVEL CREATION
protected function createLevel():void {
createWalls();
createPortals();
createEnemies();
createItems();
//CREATE PLAYER
var playerClass:Class = getAssetClass(_currentLevel.
player.@spriteClass);
_player = new playerClass();
_player.x = Number(_currentLevel.player.@x) * Number
(_currentLevel.@gridSquareSize);
_player.y = Number(_currentLevel.player.@y) * Number
(_currentLevel.@gridSquareSize);
addChild(_player as DisplayObject);
}
There is a lot going on in this method; it calls individual methods
for creating each type of core object, and then creates the player
Sprite. I
ll show all of the creation methods back to back, as they are
largely similar in structure.
'
protected function createWalls():void {
_walls = new Array();
var walls:XMLList = _currentLevel.walls.children();
for (var i:int = 0; i < walls.length(); i++) {
var wallClass:Class = getAssetClass(walls[i].
@spriteClass);
var wallSprite:IWall = new wallClass();
wallSprite.x = Number(walls[i].@x) * Number
(_currentLevel.@gridSquareSize);
wallSprite.y = Number(walls[i].@y) * Number
(_currentLevel.@gridSquareSize);
_walls.push(wallSprite);
var gridReference:GridReference = _collisionGrid.
getGridReference(Number(walls[i].@x),
Number(walls[i].@y));
Search Nedrilad ::




Custom Search