首页 > 其他 > 详细

cocos2dx CCTransition各个子项

时间:2020-05-14 01:35:17      阅读:85      评论:0      收藏:0      [点我收藏+]

1、CCTransitionProgress

该类继承了CCTransitionScene,并且有两个子类:实现了顺时针跟逆时针的进度切屏动作。

void CCTransitionProgress::onEnter()
{
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    CCRenderTexture *texture = CCRenderTexture::create((int)size.width, (int)size.height);
    texture->getSprite()->setAnchorPoint(ccp(0.5f,0.5f));
    texture->setPosition(ccp(size.width/2, size.height/2));
    texture->setAnchorPoint(ccp(0.5f,0.5f));
    texture->clear(0, 0, 0, 1);
    texture->begin();
    m_pSceneToBeModified->visit(); // 用RenderTexture截屏,将当前的显示的scene截屏。具体可以看RenderTexture的使用方法,这里不作具体说明。
    texture->end();

    hideOutShowIn(); // 已经把out的截屏,则可以把它隐藏掉了
    // 将截完的图片从texture取出来放到ProgressTimer
    CCProgressTimer *pNode = progressTimerNodeWithRenderTexture(texture);//两个子类重写了该方法,实现顺时针或者逆时针的操作,其实在本类,该函数更应该使用纯虚函数。

    CCActionInterval* layerAction = (CCActionInterval*)CCSequence::create(
        CCProgressFromTo::create(m_fDuration, m_fFrom, m_fTo), // 这里使用的是从100到0,是因为刚开始是全部遮挡住的所以是100,最终我们需要的是将out层消失,所以最终是需要0
        CCCallFunc::create(this, callfunc_selector(CCTransitionProgress::finish)), 
        NULL);
    // run the blend action
    pNode->runAction(layerAction);

    // 这里将pNode放到上一层,确保能够顶层显示(out的精灵图片)
    addChild(pNode, 2, kCCSceneRadial);
}

类似于进度切换的,如果需要另外的风格,则可以参照对应的子类进行实现:CCTransitionProgressRadialCCW,CCTransitionProgressRadialCW;比如这里抄CCTransitionProgressRadialCW自己重写一个

技术分享图片
class CCTransitionProgressRadialME : public CCTransitionProgress
{
public:
    static CCTransitionProgressRadialME* create(float t, CCScene* scene) {
        CCTransitionProgressRadialME* pScene = new CCTransitionProgressRadialME();
        if (pScene && pScene->initWithDuration(t, scene))
        {
            pScene->autorelease();
            return pScene;
        }
        CC_SAFE_DELETE(pScene);
        return NULL;
    }
protected:
    virtual CCProgressTimer* progressTimerNodeWithRenderTexture(CCRenderTexture* texture) {
        CCSize size = CCDirector::sharedDirector()->getWinSize();

        CCProgressTimer* pNode = CCProgressTimer::create(texture->getSprite());

        // but it is flipped upside down so we flip the sprite
        pNode->getSprite()->setFlipY(true);
        pNode->setType(kCCProgressTimerTypeRadial);

        //    Return the radial type that we want to use
        pNode->setReverseDirection(false);
        pNode->setPercentage(100);
        pNode->setPosition(ccp(size.width / 2, size.height / 2));
        pNode->setAnchorPoint(ccp(0.5f, 0.5f));

        return pNode;
    }

};
View Code

具体的可以实现自己想要的功能。

cocos2dx CCTransition各个子项

原文:https://www.cnblogs.com/czwlinux/p/12886004.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!