Game Development Reference
In-Depth Information
Initializing the Game
Initializing the game consists primarily of building the elements that will make the game. The game is split up into
four major areas, most being containers that hold several display objects. The
initGame
function calls each of these
game-building functions (see Listing 7-8).
Listing 7-8.
The initGame Function Kicks Off a Series of Game-Building Functions
function initGame() {
buildTitle();
buildDiceTray();
buildScoreCard();
buildScoreboard();
}
Each function will create each of the four areas of the game, which include the
game title
, the
dice tray
where
the player will roll and hold dice, the
scorecard
where the player will choose categories to score in, and finally,
the
scoreboard
that displays the section scores.
Building the Game Title
The game title is a simple sprite that sits on top of the screen. This sprite is created in the
buildTitle
function, shown
in Listing 7-9.
Listing 7-9.
The Fakezee Title Sprite
function buildTitle() {
title = new createjs.Sprite(spritesheet, 'logoSmall');
title.regX = title.getBounds().width / 2;
title.x = canvas.width / 2;
title.y = TITLE_YPOS;
//title.alpha = 0;
stage.addChild(title);
}
After the title is created, the
getBounds
method is used to retrieve the width of the sprite and is used to set its
registration point and centered on the stage. The title's
alpha
is set to 0 before added to the stage.
■
Visibility and alpha values for various objects will be set to hidden, but commented out as you build the game
elements. these will eventually be uncommented when it comes time to write their
reveal
animations.
Note
Figure
7-3
shows the Fakezee title screen on the stage.