Game Development Reference
In-Depth Information
Figure 5-15. All cards after animating to their random positions
Flipping the Cards
Before adding the cards to the stage, a click event listener was added that will fire the function flipCard . When two
cards are flipped, they are evaluated in the function evalCardsFlipped . These functions are shown in Listing 5-27.
Listing 5-27. Flipping the Cards and Checking for Matches
function flipCard(e) {
if (cardsFlipped.length === 2) {
return;
}
var card = e.target
card.mouseEnabled = false;
card.getChildByName('back').visible = false;
cardsFlipped.push(card);
if (cardsFlipped.length === 2) {
evalCardsFlipped();
}
}
 
Search WWH ::




Custom Search