Game Development Reference
In-Depth Information
createjs.Tween.get(totalScoreMsg).to({alpha:1}, 500);
createjs.Tween.get(scoreboard).to({alpha:1}, 500);
}
All objects are simultaneously faded in, and the entire game is now visible and ready to play.
Playing the Rounds
It's now time to program the game logic for Fakezee. There were a few listeners that were set on display objects as as
they were built, which will roll and hold the dice, and choose sections to score on. Each round starts with rolling and
holding dice, which will be covered in this section.
Rolling the Dice
Rolling the dice is triggered by clicking on the rollBtn container. This container holds a text object that displays the
number of rolls available, which will be three at the beginning of each round. Listing 7-21 shows the handler function
that is called when clicking the Roll button.
Listing 7-21. The rollDice Function Rolls the Dice by Playing the Dice Sprites
function rollDice(e) {
var i, die;
var rollBtn = e.currentTarget;
var rollsTxt = rollBtn.getChildByName('rollsTxt');
enableDice(false);
scoreCard.mouseEnabled = false;
rollBtn.mouseEnabled = false;
rollBtn.alpha = .7;
rollsLeft -= 1;
rollsTxt.text = rollsLeft;
for (i = 0; i < NUM_DICE; i++) {
die = diceTray.getChildByName('die' + i);
if (die.hold) {
continue;
}
die.framerate = Math.floor(Math.random() * 10) + 20;
die.play();
}
setTimeout(stopDice, 1000);
}
A reference to the roll button is stored by accessing the currentTarget property of the event passed into
the function.
var rollBtn = e.currentTarget;
 
Search WWH ::




Custom Search