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; } };
具体的可以实现自己想要的功能。
原文:https://www.cnblogs.com/czwlinux/p/12886004.html