Game Development Reference
In-Depth Information
will create for the game in this chapter will be a child of the Game.as base class. It will override
some of the Game.as base classes and hold the custom logic for the game.
//Game is our custom class to hold all logic for the game.
private var game:Game;
The wait variables
These variables are used for the simple wait period in the STATE_SYSTEM_WAIT state. waitTime
can be set to a different value each time it is used. 30 is the default. We have set the frame rate
for our application framework to 30 frames per second, so this would be a one second wait time.
30 frame ticks equals 1 second of time in our game timer if the frame rate is set to 30. waitCount
is incremented each frame when a wait is occurring. When waitCount==waitTime , the control
moves to the next state.
//waitTime is used in conjunction with the STATE_SYSTEM_WAIT state
// it suspends the game and allows animation or other processing to
//finish
private var waitTime:int = 30;
private var waitCount:int=0;
The constructor function definition
The constructor for GameFrameWork.as does not contain any code. It is simply a placeholder. We
will subclass GameFrameWork. as to create the unique Main.as for each game. The Main.as
constructor will contain code to call the init function override.
public function GameFrameWork() {
}
The init function definition
The init() function is simply a stub to be overridden by the Main.as subclass of
GameFrameWork.as .
The setApplicationBackGround function definition
This function accepts in parameters to create a basic back ground for the game. The width,
height, transparency Boolean, and color values for the back ground are passed and used to
instantiate the appBackBitmapData and place it on to the display list.
The startTimer function definition
This function will be called by the Main.as subclass inside its init function. It will use the
frameRate variable to create the timerPeriod . Since the timerPeriod must be expressed in
milliseconds (1,000/1 of a second equals a timerPeriod of 1000 or a single second), we simply
divide the frameRate into 1,000 to get the number of times per second that the timer must run. In
the case of a frameRate that is set to 30 ticks for example, the timerPeriod would be 33.33.
Search WWH ::




Custom Search