Game Development Reference
In-Depth Information
rate independent of the .swf file's frame rate (FPS). The .swf file can have a frame rate setting of
25 (for example), but the game can run at a 30 frame ticks a second. To do this, we first set the
frameRate to the desired number of frame update ticks we want per second (30). When Main.as
calls the startTimer function (described in detail when we get to the section on the init
function), the gameTimer is put into action. First, we will calculate the timerPeriod value as 1000 /
frameRate . With the updateAfterEvent function call (in the runGame function), we help to smooth
out the render of the screen by asking the Flash display engine to update at the rate of the Timer ,
not the frame rate set in the .swf . So, going back to our example, if the game SWF is set to run at
25 FPS, and the frameRate is set to 30 ticks, the updateAfterEvent will help to smooth out the
rendering of the screen by asking the Flash display engine to update at the timer tick rate (30),
not the .swf file's FPS setting (25).
The timerPeriod will be passed into the Timer instance and the game will attempt to run at this
rate. We say “attempt” because if the game includes too many on screen moving objects or more
logic than can be computed inside the timerPeriod number of milliseconds (or a combination of
both), then there will be a noticable slowdown in the game screen updates. In later chapters, we
will add functionality to the runGame function to mitigate some of these issues.
The screen definition variables
The screen definition variables create instances of our BasicScreen class. This is a rather simple
class that allows a single positional text box and an OK button on the screen. We will use this
simple screen for the title, instructions, level, and game over screens. We will customize each
screen when we create the init function override in our game's Main.as class. Note that the
levelInText is a special variable. Setting this string to a default value will allow the leveInScreen
to display some default text along on each new level. This text can be combined with dynamic
text to create a screen that says something like Level 1 with the word “Level” being the default text
and the number “1” being the dynamic text.
public var titleScreen:BasicScreen;
public var gameOverScreen:BasicScreen;
public var instructionsScreen:BasicScreen;
public var levelInScreen:BasicScreen;
public var levelInText:String;
public var screenTextFormat:TextFormat;
public var screenButtonFormat:TextFormat;
We also create two TextFormat objects that will be used for defining the format of the text on the
screens and the format of the button text.
The ScoreBoard variables
The scoreBoard instance of the ScoreBoard class will handle a simple heads up display (HUD) for
the user with information such as the current score. It is a simple framework class that will be
customized in the init function override in each game's Main.as class. The changes will depend
on the game that is to be created. We also define a TextFormatObject for the basic look of the
text for our scoreboard text: scoreBoardTextFormat .
The Game object variable
The Game object, represented by the variable simply named game , is an instance of the Game class.
The Main.as class's init function override will inistantiate this. For example, the StubGame.as we
Search WWH ::




Custom Search