Game Development Reference
In-Depth Information
override public function setRendering(profiledRate:int, framerate:int):void {
var percent:Number=profiledRate / framerate
trace("framepercent=" + percent);
trace("stage=" + stage);
if (percent>=.85) {
frameRateMultiplier = 2;
}
trace("frameRateMultiplier=" + frameRateMultiplier);
}
The setRendering function is public and called from the Main.as class. It passed in the
profiledRate from the FrameRateProfiler class as well as the desired frameRate for the game. If
the profiledRate rate is equal to or greater than 85 percent of the desired frameRate, the
frameRateMultipler variable is set to 2. This setup allows us to double the number of particles for
explosions. We will also double the size of the particle pool. This function serves as just a small
example of how you can use the profiled information to create a unique experience for different
powered computers.
We can't access the stage variable yet, because when the init function is called, the
BlasterMines.as game has not been added to the Main.as stage display list. The stage will be
available when the newGame function is called. In that function, we will set the stage.quality
based on this new frameRateMultiplier value.
Next up is the init function where we create objects and set up the manager classes:
private function init():void {
this.focusRect = false;
//init radar
radarBitmap.x = 420;
radarBitmap.y = 230;
radarBitmap.scaleX = .2;
radarBitmap.scaleY = .2;
createLookupTables();
player.createPlayerShip(spriteGlowFilter);
projectileManager.createProjectiles(spriteGlowFilter);
projectileManager.createProjectilePool(50);
canvasBitmap.scrollRect = new Rectangle(200,200,400,400);
addChild(canvasBitmap);
addChild(radarBitmap);
}
The init function sets up all of the initial information for the game. We previously discussed
radarBitmap and canvasBitmap.scrollRect in the optimization sections. The createLookupTables
function was also discussed previously, and you will see the createPlayerShip, createProjectiles,
and createProjectilePool functions in detail when we look at the associated manager classes very
shortly. One thing to note about all of these is that they only need to be called and created one
time for the entire gaming session. There will never be a need to call them again.
Search WWH ::




Custom Search