I've been experimenting with a card game and I'm interested in adding a card flip animation to it.
I searched online for solutions, but most of them involve jquery (which I'd rather not use for just one animation) or CSS3 (I found this example interesting). Unfortunately, I didn't have much success with these options.
The javascript game includes the following code (from cardgamecore.js):
playingCard.redrawCardImage()
- Forces a card to redraw
playingCard.showFace(bool: face)
- Sets the card to be either face up or face down, and redraws if necessary. true = face up, false = face down.
playingCard.prototype.redrawCardImage = function () {
// Set or change the image showing on the card face
if( !this.faceImage || !this.cardSet.backImage ) { return; }
// Bug in Firefox - alt attributes do not change unless they are made _before_ an SRC change
this.cardImage.setAttribute('alt',this.wayup?(this.cardSet.cardNames[this.number-1]+' '+this.suit):this.cardSet.cardWord);
this.cardImage.src = this.wayup ? this.faceImage : this.cardSet.backImage;
};
playingCard.prototype.showFace = function (oWhich) {
// Used to flip a card over
if( this.redrawNewImage != oWhich ) {
this.wayup = oWhich;
this.redrawCardImage();
}
};
So when a card is facing down, then playingCard.showFace = false
. When you click on it, playingCard.showFace = true
and the image gets redrawn. At this point, I want to add a smooth flip animation to the card.
But how can I achieve this effect?