昨天吃饭看见同事演示他做的翻牌效果,感觉不错,我心血来潮也来搞个,很简单直接上代码。
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()> || m_pBack->numberOfRunningActions()>)
{
return;
}
static const float fDuration = 2.0f; auto* pSeq1 = CCSequence::create( CCOrbitCamera::create(fDuration*0.5f, , , m_fDeltaFlipAngle, , , ),
CCHide::create(),
NULL);
m_fDeltaFlipAngle+=90.0f;
auto* pSeq2 = CCSequence::create( CCDelayTime::create(fDuration*0.5f),
CCShow::create(),
CCOrbitCamera::create(fDuration*0.5f, , , m_fDeltaFlipAngle, , , ),
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;
};