Game Development Reference
In-Depth Information
Updating the Score
When a score is determined, the category needs to display it, and the score messaging inside the scoreboard and
scorecard should be updated. The sprite frame for the selected category is now updated to make room for text and is
added using the udpateScore function, shown in Listing 7-25.
Listing 7-25. The udpateScore Function Creates a Text Object and Places It Above the Chosen Category
function updateScore(btn, score) {
var label = new createjs.Text(score, '27px Calibri', '#FFF');
var labelXOffset;
var labelYOffset;
switch (btn.section) {
case 1:
section1Score += score;
labelXOffset = 70;
labelYOffset = 11;
break;
case 2:
section2Score += score;
if (btn.name == 'fakezee') {
labelXOffset = 0;
labelYOffset = -15;
}
else {
labelXOffset = 35;
labelYOffset = 10;
}
break;
}
label.name = 'label';
label.textAlign = 'center';
label.x = btn.x + labelXOffset;
label.y = btn.y + labelYOffset;
scoreCard.addChild(label);
}
A text object is created and given a value of the score passed into the function. A few positioning variables are
then declared and will be given values based on the section of the category button selected. The appropriate score is
also updated using this same section value.
Because the buttons in section one are graphically different than those in section two, the text offset position
needs to be different. Using the section value of the button passed into the function, the offset values are set.
The giant Fakezee button in the middle has its own layout as well, and is considered in the case of section two.
case 2:
section2Score += score;
if (btn.name == 'fakezee') {
labelXOffset = 0;
labelYOffset = -15;
}
 
Search WWH ::




Custom Search