How to create a flip card animation? (Javascript)

Hi,

Who know how to create the flip card animation in Javascript code?

Flip Animation look like the picture bellow:


(from :http://gameit.ro/2014/04/card-flipping-effect-using-cocos2d-x-without-fisheye-distortion/)

My Code:

properties: {
        card: {
            default: null, 
            type: cc.Node
        },
},
onLoad: function () {
        this.flip();
},
flip: function(){
        let front = this.card.getChildByName("front");
        let back = this.card.getChildByName("back");
        var rotationBy = cc.rotateBy(1, 0, 90);
        
        let changeOpacity = cc.callFunc(() => {
            front.opacity = 0 ; 
        });
        let flipBack = cc.callFunc(() => {
            this.flip2(); 
        });
        let seq = cc.sequence(rotationBy, changeOpacity, rotationBy, cc.delayTime(2), flipBack);
        this.card.runAction(seq);
},
flip2: function(){
        let front = this.card.getChildByName("front");
        let back = this.card.getChildByName("back");
        var rotationBy = cc.rotateBy(1, 0, 90);
        
        let changeOpacity = cc.callFunc(() => {
            front.opacity = 255; 
        });
        let flipBack = cc.callFunc(() => {
            this.flip(); 
        });
        let seq = cc.sequence(rotationBy, changeOpacity, rotationBy, cc.delayTime(2), flipBack);
        this.card.runAction(seq);
},

Hi @asming2007,

without 3D perspective, you can use the ScaleX to flip the card. It’s the “cheap” solution.

Best regards,
Zsolt

Hi @PZsolt27,

Thanks your answer.
I’m still need 3D perspective, it is possible to do with 3D perspective?

Hi @asming2007,

as far as I know Cocos Creator is for 2D only, we cannot create 3D objects.

Best regards,
Zsolt