coco2dx实现翻拍效果

昨天吃饭看见同事演示他做的翻牌效果,感觉不错,我心血来潮也来搞个,很简单直接上代码。

class FlipCard : public CCNode
{
public:

    CREATE_FUNC(FlipCard);

    virtual bool init()
    {
        if (CCNode::init())
        {
            m_pFront = CCNode::create();
            m_pBack =CCNode::create();
            m_pBack->setVisible(false);
            addChild(m_pBack);
            addChild(m_pFront);
            m_fDeltaFlipAngle = 0.0f;
            return true;
        }
        return false;
    }

    void Flip()
    {
        if (m_pFront->numberOfRunningActions()>0 || m_pBack->numberOfRunningActions()>0)
        {
            return;
        }
        static const float fDuration = 2.0f;

    auto* pSeq1 = CCSequence::create( CCOrbitCamera::create(fDuration*0.5f, 1, 0, m_fDeltaFlipAngle, 90, 0, 0),
        CCHide::create(),
        NULL);
    m_fDeltaFlipAngle+=90.0f;
    auto* pSeq2 = CCSequence::create( CCDelayTime::create(fDuration*0.5f),
        CCShow::create(),
        CCOrbitCamera::create(fDuration*0.5f, 1, 0, m_fDeltaFlipAngle, 90, 0, 0),
        NULL);
    m_fDeltaFlipAngle+=90.0f;
        m_pFront->runAction(pSeq1);
        m_pBack->runAction(pSeq2);

        auto p = m_pFront;
        m_pFront = m_pBack;
        m_pBack = p;
    }

    CCNode* m_pFront;
    CCNode* m_pBack;
    float    m_fDeltaFlipAngle;
};

 

 

posted @ 2014-01-12 21:12  MrBlue  阅读(402)  评论(0编辑  收藏  举报