Game Development Reference
In-Depth Information
if (show) {
TweenMax.to(card, .5, { onComplete:card.show,
rotationY:90, ease:Back.easeIn });
TweenMax.to(card, .4, { onComplete:checkCards,
rotationY:0, ease:Quad.easeOut, delay:.5 });
} else {
TweenMax.to(card, .4, { onComplete:card.hide,
rotationX:90, ease:Quad.easeIn });
TweenMax.to(card, .5, { rotationX:0, ease:Bounce.
easeOut, delay:.4 });
}
}
When a card is clicked, the selectCard method is called. If no
cards are selected, the clicked card becomes the first of a compari-
son pair. If the same card is selected again, it is flipped back over.
Finally, if a second card is clicked, it is added to the pair and
flipped. The flipCard method is the first place we use any
TweenMax functionality. By default, this function will show the
card face; if the second parameter is false, it will hide the card
again. The most basic TweenMax syntax involves the two static
methods to and from .The to method creates a TweenMax object
that will be automatically disposed of when the tween finishes. The
first parameter is the object that you want to tween, and
the second parameter is the amount of time you want it to take in
seconds. The final parameter is an object containing all the proper-
ties you want the tween to change, as well as information about
which easing equation to use and what function to call when the
tween is finished. TweenMax also supports a full event listener
model, but it
s a little overkill in this very simple instance.
When a card is flipped to be shown, the game first animates
its rotationY property to appear to flip horizontally. Note that the
easing method for this first tween is part of the Back class. The
card will appear to turn the opposite direction for a brief moment
before snapping toward its intended direction. When this tween is
complete, it calls the card
'
s show method and begins a tween
restoring it to its original state. Once this second tween is complete,
the checkCard method is called, which we will examine next. If the
card is being hidden, the tween animates the card
'
s rotationX
property to flip the card vertically. When the card finally returns to
its hidden state, the tween animates it using the Bounce easing
class. This will give the effect of the card hitting a rubber surface.
'
protected function checkCards():void {
if (!_selectedCards[1]) {
activateCards();
} else {
Search Nedrilad ::




Custom Search