Game Development Reference
In-Depth Information
//section 1
txt = createScoreboardText('Section 1 Score:', sec1XPos, padding)
scoreboard.addChild(txt);
xPos = txt.getMeasuredWidth() + txt.x + padding;
txt = createScoreboardText(section1Score, xPos, padding,
'section1Txt');
scoreboard.addChild(txt);
//section 2
txt = createScoreboardText('Section 2 Score:', sec2XPos, padding);
scoreboard.addChild(txt);
xPos = txt.getMeasuredWidth() + txt.x + padding;
txt = createScoreboardText(section2Score, xPos, padding,
'section2Txt');
scoreboard.addChild(txt);
//bonus
txt = createScoreboardText('Bonus Score:', bonusXPos, padding);
scoreboard.addChild(txt);
xPos = txt.getMeasuredWidth() + txt.x + padding;
txt = createScoreboardText(bonusScore, xPos, padding, 'bonusTxt');
scoreboard.addChild(txt);
stage.addChild(scoreboard);
}
function createScoreboardText(label, x, y, name) {
var txt = new createjs.Text(label, '16px Calibri', '#FFF');
txt.x = x;
txt.y = y;
txt.name = name;
return txt;
}
The scoreboard game variable is used to create the scoreboard container. It contains one background sprite and
six text objects. Three of the text objects are labels, and the other three will be updated with scores after each turn.
This function builds and places each text object horizontally across the board. The text objects that need to be
updated are given names so they are easily accessible when updating them. The actual creation of each text object
is built and returned in a separate function named createScoreboardText . All text uses the same styling, so this
function is used to split up the code and make things a little easier to read. The text-creating function is passed the
necessary values to create the text, and passes back the new text object. Figure 7-9 shows the scoreboard added to
the stage.
 
Search WWH ::




Custom Search