Game Development Reference
In-Depth Information
else {
labelXOffset = 35;
labelYOffset = 10;
}
break;
The text is then appropriately positioned above its corresponding section and added to the scorecard container.
Figure 7-14 demonstrates the ones and threes sections updated after being clicking.
Figure 7-14. The category buttons when scores are applied
After a category is scored, the rest of the scoring messages need to update as well. The updateScoreboard
function updates the appropriate text objects (see Listing 7-26).
Listing 7-26. All Score Messaging is Updated in the updateScoreboard Function
function updateScoreboard() {
var section1Txt = scoreboard.getChildByName('section1Txt');
var section2Txt = scoreboard.getChildByName('section2Txt');
var bonusTxt = scoreboard.getChildByName('bonusTxt');
var totalScoreTxt = scoreCard.getChildByName('scoreTxt');
section1Txt.text = section1Score;
section2Txt.text = section2Score;
bonusTxt.text = bonusScore;
totalScoreTxt.text = totalScore = (section1Score + section2Score + bonusScore);
}
Each text object is referenced by its name and accessed via the container to which it belongs. The game variables
that hold the scores were updated in the previous function, so their values are simply assigned to their corresponding
text object. The total score message is then updated to be the sum of all scores.
 
Search WWH ::




Custom Search