Game Development Reference
In-Depth Information
Creating our game instance
The game variable is defined in the
GameFrameWork.as
file, but instantiated in
Main.as
. We will
create the Game subclass called instance
StubGame.as
in the next section.
game = new StubGame();
Setting the application back ground
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 our stub game, we are creating a 400, 400 opaque black background.
setApplicationBackGround(400, 400, false, 0x000000);
Creating the score board
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
for the look of the
scoreBoard
text
(
scoreBoardTextFormat)
and then create each text element we will need on the
scoreBoard
. We
only have a single element on the
scoreBoard
in this stub game. We pass in the constant,
SCORE_BOARD_CLICKS
, which was defined in the variable definition section of this
Main.as
class file,
into the public
scoreBoard.createTextElement
function along with the definition of the
SideBySideScoreElement
class instance for this
scoreBoard
element.
scoreBoard = new ScoreBoard();
addChild(scoreBoard);
scoreBoardTextFormat= new TextFormat("_sans", "11", "0xffffff",
"true");
scoreBoard.createTextElement(SCORE_BOARD_CLICKS, new
SideBySideScoreElement(25, 5, 15, "Clicks", scoreBoardTextFormat,
25, "0", scoreBoardTextFormat));
In this definition, we are setting the
"Clicks"
string label to reside at the
25, 5
location on the
scoreBoard
. We have also set a
15
pixel buffer between the
"Clicks"
label text and the value that
will be displayed and have given the label a width of
25
pixels. We have set the
TextFormat
for
both the label and the content to the
scoreBoardTextFormat
we defined earlier.
Creating the title screen
All of the
BasicScreen
instances will be set up in a similar manner. All are defined in the
GameFrameWork.as
file and instantiated in the
Main.as init
function. The first thing we do is set
up a separate
TextFormat
object (
screenTextFormat
) to be shared between all of the screens. We
could actually use a different
TextFormat
for each screen, but for simplicity, we are using one in
this example game. We also create a
TextFormat
for
SimpleBlitButton
instances that can be
added to each
BasicScreen
instance.
screenTextFormat = new TextFormat("_sans", "16", "0xffffff", "false");
screenTextFormat.align = flash.text.TextFormatAlign.CENTER;
screenButtonFormat = new TextFormat("_sans", "12", "0x000000",
"false");