Game Development Reference
In-Depth Information
protected function createPortals():void {
_portals = new Array();
var portals:XMLList = _currentLevel.portals.children();
for (var i:int = 0; i < portals.length(); i++) {
var portalClass:Class = getAssetClass(portals[i].
var portalSprite:IPortal = new portalClass();
portalSprite.x = Number(portals[i].@x) * Number
portalSprite.y = Number(portals[i].@y) * Number
portalSprite.destination = portals[i].
for each (var requirement:XML in portals[i].
requirement) {
var gridReference:GridReference = _collisionGrid.
addChild(portalSprite as DisplayObject);
ve bolded the
most significant areas. Each of the types of Sprites adds itself to the
appropriate GridReference object, and each enemy Sprite stores a
reference to its respective GridReference. In createPortals , each por-
tal defines a new PortalRequirement object for every requirement
necessary to use that portal. Every type of Sprite is added both to
an engine-level list, as well as a grid reference, and then added to
the Stage at its specified position from the XML.
The level has now been created and is in the display list. From this
point forward, startGame and stopGame can be called on the engine,
and the player Sprite is ready to receive input. However, we
Because there is so much code to digest here, I
re going
to jump slightly out of order in the file for a moment to outline the
helper methods before we dive into the main game loop. Then, we
examine the keyboard input handlers the game uses as well.
protected function getGridPosition(sprite:ISprite):Point {
var spriteRect:Rectangle = sprite.getRect(this);
Search Nedrilad ::

Custom Search