Game Development Reference
In-Depth Information
The majority of the functionality of this engine is protected and
inaccessible from the outside.
public function startGame():void {
if (!stage) throw new Error( " PlatformEngine instance must
be added to stage before startGame() is called. " );
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown,
false, 0, true);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp,
false, 0, true);
addEventListener(Event.ENTER_FRAME, update, false, 0, true);
_previousTime = getTimer();
_gameRunning = true;
}
public function stopGame():void {
if (!stage) throw new Error(
PlatformEngine instance must
be added to stage before stopGame() is called.
"
);
stage.removeEventListener(KeyboardEvent.KEY_DOWN,
onKeyDown);
stage.removeEventListener(KeyboardEvent.KEY_UP, onKeyUp);
removeEventListener(Event.ENTER_FRAME, update);
_gameRunning = false;
"
}
Once the game is added to the Stage and has had all of its data
loaded, the startGame and stopGame methods can be called. They
handle the enterFrame and keyboard listener attachment, and also
toggle a Boolean value called _gameRunning .Thiswillbeused,
later, in case the game is stopped and disposed of before all the
game loop code has finished running.
public function get inventory():Vector. < IItem > {
return _inventory.slice();
}
One of the facets the game does expose is a copy of the
inventory vector. This allows the UI to display information about
what is in the player
s inventory. Storing everything the player
picks up allows us to tie portal requirements to specific items
later on.
'
public function get inventoryWorth():Number {
var worth:Number = 0;
for each (var item:IItem in _inventory) {
worth += item.points;
}
return worth;
}
Search Nedrilad ::




Custom Search