Game Development Reference
In-Depth Information
lastTime = getTimer();
systemFunction();
frameCounter.countFrames();
}
The Main.as class for each game will override the systemGamePlay state function from
GameFrameWork and pass this timeDifference as well as the paused variable (used to pause the
game if set to true ) into the BlasterMines runGameTimeBased function. This is the new function
that we will add to the Game base class. Here is an example of that function from the Main.as that
will we will create for BlasterMines :
override public function systemGamePlay():void {
game.runGameTimeBased(paused,timeDifference);
}
We will be creating this runGameTime -based function in the Game base class, and we will override it
in each game that needs to implement this timer. The runGameTimeBased function in
BlasterMines.as will look like the following:
override public function
runGameTimeBased(paused:Boolean=false,timeDifference:Number=1):void {
if (!paused) {
systemFunction(timeDifference);
}
}
This function is part of the BlasterMines.as internal state machine. The systemFunction will
reference the current state function. These functions must accept in the paused and
timeDifference values. Here is an example of the BlasterMines.as systemGamePlay function.
Notice that the pause functionality is applied in the previous runGameTimeBased function, so
systemGamePlay will not be called if the paused value is true.
private function systemGamePlay(timeDifference:Number=0):void {
update(timeDifference);
checkCollisions();
render();
updateScoreBoard();
checkforEndLevel();
checkforEndGame();
}
The update function for Blaster Mines must accept in the timeDifference value. Here is a snippet
of this function for demonstration:
private function update(timeDifference:Number = 0):void {
//time based movement modifier calculation
var step:Number = (timeDifference / 1000)*timeBasedUpdateModifier;
trace("timeDifference= " + timeDifference);
trace("timeDifference/1000=" + String (timeDifference / 1000));
trace("timeBasedUpdateModifier=" + timeBasedUpdateModifier);
trace("step=" + step);
Search WWH ::




Custom Search