Game Development Reference
In-Depth Information
public static const SCORE_BOARD_SCORE:String = "score";
public static const SCORE_BOARD_CLICKED:String = "clicked";
public static const SCORE_BOARD_PERCENT_NEEDED:String =
"percent needed";
public static const SCORE_BOARD_PERCENT_ACHIEVED:String =
"percent achieved";
Notice that
Main.as
extends the
GameFramework
class, which gives it access to all of the public
methods and properties of
GameFrameWork
to use as if they were its own. We will need to override
the
init
function of
GameFrameWork.as
to instantiate customize the screens and score board for
each unique game.
Defining the constructor and
init
function the constructor of our
Main.as
class simply calls the
init
function. In Chapter 12, we will create preloaders for both the Flash IDE and the Flex SDK.
The preloaders will require us to add code to out game that waits for the
Stage
object to be
available. We do not need that code for this game, so we simply call the
init
function.
The heart of this
Main.as
class is the
init
function override of the
GameFrameWork.as
file's
init
function. Here, we will modify the framework for each particular game. It is very important that you
completely understand what is going on in this function, because it will be modified and used in
every game we will create throughout this topic.
Creating our game instance
The game variable is defined on the
GameFrameWork.as
file but instantiated in
Main.as
. We will
create the
Game
subclass called instance
SuperClick.as
in the next section.
game = new SuperClick();
Setting the application background
The
appBackGroundBitmapData
variable is defined in the
GameFrameWork.as
file but set up in
Main.as
by calling the
setApplicationBackGround
public function in the
Main.as
parent class,
GameFrameWork
. For Super Click, we are creating a 400
400-pixel opaque black background.
setApplicationBackGround(400, 400, false, 0x000000);
Creating the Scoreboard
The
scoreBoard
variable is defined in the
GameFrameWork.as
file and instantiated in
Main.as
. To
set up
scoreBoard
, we need to create a
TextFormat
instance for the look of the
scoreBoard
text
(
scoreBoardTextFormat)
and then create each text element we will need on the scoreboard. We
have the following four sets of text elements our
scoreBoard
instance:
scoreBoard = new ScoreBoard();
addChild(scoreBoard);
scoreBoardTextFormat= new TextFormat("_sans", "11", "0xffffff",
"true");
scoreBoard.createTextElement(SCORE_BOARD_SCORE, new
SideBySideScoreElement(25, 5, 15, "Score", scoreBoardTextFormat,
25,"0", scoreBoardTextFormat));