Game Development Reference
In-Depth Information
The state control variables
The control variables keep the system functioning within the context of the current state. The
main control variable is an instance of the Function class called systemFunction . This function
holds a reference to the current function that will be repeatedly called on each frame tick. This
saves us from having to evaluate a switch:case statement on each frame to decide which
function to call. The function is changed to a new reference by called the switchSystemState()
function and passing a new constant that represents the new state.
Optimization! switchSystemState() is the first of many optimizations we will make to the game
framework. All of these optimizations will make the Flash games run much more efficiently. These
efficiencies in the game framework will allow the actual game code to perform more complex
operations and still run with a reasonable frame rate.
The currentSystemState integer variable holds a number representing the constant of the current
state the system is running. The nextSystemState contains the constant integer value for the
state to transition to after this state is complete. The lastSystemState variable holds the integer
constant of the previous system state. This is used in the rare occurrence that the game loop
needs to return to the previous system state.
The lastSystemState variable will become useful when we use a shared state such as
STATE_SYSTEM_WAIT . The STATE_SYSTEM_LEVEL_IN state will implement a 30-millisecond delay
before moving on to the STATE_SYSTEM_GAME_PLAY state. The nextSystemState will be
STATE_SYSTEM_WAIT and the lastSystemState will be STATE_SYSTEM_LEVEL_IN . When the 30-
millisecond wait time has expired, the waitCompleteListener function will be called. It will use the
lastSystemState to determine where the processing was before the wait was started. You'll see
this in detail later in this chapter when we examine the waitCompleteListener function.
The background fill variables
All Flash applications have a background color of some type. No matter what game we are going
to be creating, the framework can control this background color. You should never rely on the
background color setting in HTML for your Flash application's background color. This leaves the
HTML embed code with control over major aspect of your application. If you are creating a viral
game to be placed on game portals, you will lose control of your game's background color, and it
will default to what ever the game portal operators have selected as the standard background
color in their embed code. The framework allows you to override the HTML settings here by
placing a simple colored Bitmap behind the entire application. We will simply define a BitmapData
object called appBackBitmapData and a Bitmap object called appBackBitmap that will be used to
place the BitmapData onto the displayList .
We will not define the background in the GameFrameWork.as file, but rather the Main.as subclass of
the GameFrameWork will set the background if needed in its init function override.
The timer variables
The timer will control the frame rate of the game and help smooth out the display by employing
the TimerEvent.updateAfterEvent method. The frameRate variable will be defined in Main.as as
the number of frame ticks per second we want our game timer to run.
The most important thing to note is that we are making use of the built-in Timer class ( gameTimer ).
We are not using the standard EnterFrame event. This allows us to create our own frame rate for
the game and specify it in the frameRate variable. By doing this, we can control game timer tick
Search WWH ::




Custom Search