如何用cocos2d-x翻转一张卡片

时间:2014-09-09 07:04:11

标签: cocos2d-x cocos2d-x-3.0

我需要翻转卡片才能看到它的背面,然后是侧面,然后逐渐使用这样的动画:https://www.youtube.com/watch?v=te0Je0y4zU0。我怎么用cocos2d-x做到这一点?我查看了OrbitCameraRotateBy in 3D测试。它们非常接近我想要的那个,唯一的问题是,当精灵转过来时,我看不到背面(因为应该是另一个纹理,但后面的相机也是如此)。我知道我应该使用2个精灵来获得效果,但我应该怎么做,我不知道。我应该用不同的Z顺序定位2个精灵吗?请指教。

4 个答案:

答案 0 :(得分:0)

试试这个:

float duration = 2.0f;
auto actionBy = RotateBy::create(duration / 2, Vec3(0, 90, 0));

backCard->runAction(RotateBy::create(0, Vec3(0, 90, 0)));
frontCard->runAction( Sequence::create(
                            actionBy,
                            CallFunc::create([backCard, actionBy](){backCard->runAction(actionBy);}),
                            nullptr)

答案 1 :(得分:0)

 you need to simply do this : 

 CCRotateTo *act1= CCRotateTo::create(0.5, -180);
 CCRotateTo *act2= CCRotateTo::create(1.0, 180);

 CCSequence* act3 = CCSequence::create(act1,act2,NULL);

 sprite->runAction(act3);

答案 2 :(得分:0)

您应该查看https://www.youtube.com/watch?v=Q4fJrMvZVhI

与使用javascript的cocos2dx相同。

 reveal: function (pIsFaceUp) {
    let self = this;
    let timeFlip =0.5;
    let callFunc = cc.callFunc(function () {
        self.cardBG.spriteFrame = pIsFaceUp ? self.texFrontBG : self.texBackBG;
        self.point.node.active = pIsFaceUp;
        self.suit.node.active = pIsFaceUp;
        self.mainPic.node.active = pIsFaceUp;
        if(!pIsFaceUp)
            self.node.skewY=135;
        else
            self.node.skewY=45;
    });
    if(!pIsFaceUp)
    {
        self.node.skewY=0;
        let action = cc.skewBy(timeFlip/2,0,45);
        let action2 = cc.skewTo(timeFlip/2,0,180);
        self.node.runAction(cc.sequence(action,callFunc,action2));
    }else
    {
        self.node.skewY=180;
        let action = cc.skewBy(timeFlip/2,0,-45);
        let action2 = cc.skewTo(timeFlip/2,0,0);
        self.node.runAction(cc.sequence(action,callFunc,action2));
    }

},

答案 3 :(得分:-1)

使用2个精灵:spriteFront,spriteBack

init(首先显示spriteBack):
将spriteFront缩放为(0,1)(将X缩放为0,同时将比例Y保持为1) scale spriteBack to(1,1)

翻转动画:
scale spriteBack to(0,1)
动画结束后,
将spriteFront缩放为(1,1)

float fDuration = 0.8f;

CCArray* pArray = CCArray::create();
pArray->addObject(CCScaleTo::create(fDuration/2, 0, 1));
pArray->addObject(CCTargetedAction::create(spriteFront, CCScaleTo::create(fDuration/2, 1)));
CCFiniteTimeAction* flipCardAnimation = CCSequence::create(pArray);

spriteBack->runAction(flipCardAnimation);