123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- /****************************************************************************
- Copyright (c) 2009 Lam Pham
- Copyright (c) 2010-2012 cocos2d-x.org
- Copyright (c) 2012 Ricardo Quesada
- Copyright (c) 2013-2016 Chukong Technologies Inc.
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
- http://www.cocos2d-x.org
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
- #include "2d/CCTransitionProgress.h"
- #include "base/CCDirector.h"
- #include "2d/CCRenderTexture.h"
- #include "2d/CCProgressTimer.h"
- #include "2d/CCActionInstant.h"
- #include "2d/CCActionProgressTimer.h"
- NS_CC_BEGIN
- enum {
- kSceneRadial = 0xc001,
- };
- TransitionProgress::TransitionProgress()
- : _to(0.0f)
- , _from(0.0f)
- , _sceneToBeModified(nullptr)
- {
- }
- TransitionProgress* TransitionProgress::create(float t, Scene* scene)
- {
- TransitionProgress* newScene = new (std::nothrow) TransitionProgress();
- if(newScene && newScene->initWithDuration(t, scene))
- {
- newScene->autorelease();
- return newScene;
- }
- CC_SAFE_DELETE(newScene);
- return nullptr;
- }
- // TransitionProgress
- void TransitionProgress::onEnter()
- {
- TransitionScene::onEnter();
- setupTransition();
-
- // create a transparent color layer
- // in which we are going to add our rendertextures
- Size size = Director::getInstance()->getWinSize();
- // create the second render texture for outScene
- RenderTexture *texture = RenderTexture::create((int)size.width, (int)size.height,Texture2D::PixelFormat::RGBA8888,GL_DEPTH24_STENCIL8);
- texture->getSprite()->setAnchorPoint(Vec2(0.5f,0.5f));
- texture->setPosition(size.width/2, size.height/2);
- texture->setAnchorPoint(Vec2(0.5f,0.5f));
- // render outScene to its texturebuffer
- texture->beginWithClear(0, 0, 0, 1);
- _sceneToBeModified->visit();
- texture->end();
- // Since we've passed the outScene to the texture we don't need it.
- if (_sceneToBeModified == _outScene)
- {
- hideOutShowIn();
- }
- // We need the texture in RenderTexture.
- ProgressTimer *node = progressTimerNodeWithRenderTexture(texture);
- // create the blend action
- auto layerAction = Sequence::create(
- ProgressFromTo::create(_duration, _from, _to),
- CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
- nullptr);
- // run the blend action
- node->runAction(layerAction);
- // add the layer (which contains our two rendertextures) to the scene
- addChild(node, 2, kSceneRadial);
- }
- // clean up on exit
- void TransitionProgress::onExit()
- {
- // remove our layer and release all containing objects
- removeChildByTag(kSceneRadial, true);
- TransitionScene::onExit();
- }
- void TransitionProgress::sceneOrder()
- {
- _isInSceneOnTop = false;
- }
- void TransitionProgress::setupTransition()
- {
- _sceneToBeModified = _outScene;
- _from = 100;
- _to = 0;
- }
- ProgressTimer* TransitionProgress::progressTimerNodeWithRenderTexture(RenderTexture* /*texture*/)
- {
- CCASSERT(false, "override me - abstract class");
- return nullptr;
- }
- // TransitionProgressRadialCCW
- ProgressTimer* TransitionProgressRadialCCW::progressTimerNodeWithRenderTexture(RenderTexture* texture)
- {
- Size size = Director::getInstance()->getWinSize();
- ProgressTimer* node = ProgressTimer::create(texture->getSprite());
- // but it is flipped upside down so we flip the sprite
- node->getSprite()->setFlippedY(true);
- node->setType(ProgressTimer::Type::RADIAL);
- // Return the radial type that we want to use
- node->setReverseDirection(false);
- node->setPercentage(100);
- node->setPosition(size.width/2, size.height/2);
- node->setAnchorPoint(Vec2(0.5f,0.5f));
-
- return node;
- }
- TransitionProgressRadialCCW* TransitionProgressRadialCCW::create(float t, Scene* scene)
- {
- TransitionProgressRadialCCW* newScene = new (std::nothrow) TransitionProgressRadialCCW();
- if(newScene && newScene->initWithDuration(t, scene))
- {
- newScene->autorelease();
- return newScene;
- }
- CC_SAFE_DELETE(newScene);
- return nullptr;
- }
- // TransitionProgressRadialCW
- TransitionProgressRadialCW* TransitionProgressRadialCW::create(float t, Scene* scene)
- {
- TransitionProgressRadialCW* newScene = new (std::nothrow) TransitionProgressRadialCW();
- if(newScene && newScene->initWithDuration(t, scene))
- {
- newScene->autorelease();
- return newScene;
- }
- CC_SAFE_DELETE(newScene);
- return nullptr;
- }
- ProgressTimer* TransitionProgressRadialCW::progressTimerNodeWithRenderTexture(RenderTexture* texture)
- {
- Size size = Director::getInstance()->getWinSize();
-
- ProgressTimer* node = ProgressTimer::create(texture->getSprite());
-
- // but it is flipped upside down so we flip the sprite
- node->getSprite()->setFlippedY(true);
- node->setType( ProgressTimer::Type::RADIAL );
-
- // Return the radial type that we want to use
- node->setReverseDirection(true);
- node->setPercentage(100);
- node->setPosition(size.width/2, size.height/2);
- node->setAnchorPoint(Vec2(0.5f,0.5f));
-
- return node;
- }
- // TransitionProgressHorizontal
- TransitionProgressHorizontal* TransitionProgressHorizontal::create(float t, Scene* scene)
- {
- TransitionProgressHorizontal* newScene = new (std::nothrow) TransitionProgressHorizontal();
- if(newScene && newScene->initWithDuration(t, scene))
- {
- newScene->autorelease();
- return newScene;
- }
- CC_SAFE_DELETE(newScene);
- return nullptr;
- }
- ProgressTimer* TransitionProgressHorizontal::progressTimerNodeWithRenderTexture(RenderTexture* texture)
- {
- Size size = Director::getInstance()->getWinSize();
- ProgressTimer* node = ProgressTimer::create(texture->getSprite());
-
- // but it is flipped upside down so we flip the sprite
- node->getSprite()->setFlippedY(true);
- node->setType( ProgressTimer::Type::BAR);
-
- node->setMidpoint(Vec2(1, 0));
- node->setBarChangeRate(Vec2(1,0));
-
- node->setPercentage(100);
- node->setPosition(size.width/2, size.height/2);
- node->setAnchorPoint(Vec2(0.5f,0.5f));
- return node;
- }
- // TransitionProgressVertical
- TransitionProgressVertical* TransitionProgressVertical::create(float t, Scene* scene)
- {
- TransitionProgressVertical* newScene = new (std::nothrow) TransitionProgressVertical();
- if(newScene && newScene->initWithDuration(t, scene))
- {
- newScene->autorelease();
- return newScene;
- }
- CC_SAFE_DELETE(newScene);
- return nullptr;
- }
- ProgressTimer* TransitionProgressVertical::progressTimerNodeWithRenderTexture(RenderTexture* texture)
- {
- Size size = Director::getInstance()->getWinSize();
-
- ProgressTimer* node = ProgressTimer::create(texture->getSprite());
-
- // but it is flipped upside down so we flip the sprite
- node->getSprite()->setFlippedY(true);
- node->setType(ProgressTimer::Type::BAR);
-
- node->setMidpoint(Vec2(0, 0));
- node->setBarChangeRate(Vec2(0,1));
-
- node->setPercentage(100);
- node->setPosition(size.width/2, size.height/2);
- node->setAnchorPoint(Vec2(0.5f,0.5f));
-
- return node;
- }
- // TransitionProgressInOut
- TransitionProgressInOut* TransitionProgressInOut::create(float t, Scene* scene)
- {
- TransitionProgressInOut* newScene = new (std::nothrow) TransitionProgressInOut();
- if(newScene && newScene->initWithDuration(t, scene))
- {
- newScene->autorelease();
- return newScene;
- }
- CC_SAFE_DELETE(newScene);
- return nullptr;
- }
- void TransitionProgressInOut::sceneOrder()
- {
- _isInSceneOnTop = false;
- }
- void TransitionProgressInOut::setupTransition()
- {
- _sceneToBeModified = _inScene;
- _from = 0;
- _to = 100;
- }
- ProgressTimer* TransitionProgressInOut::progressTimerNodeWithRenderTexture(RenderTexture* texture)
- {
- Size size = Director::getInstance()->getWinSize();
-
- ProgressTimer* node = ProgressTimer::create(texture->getSprite());
-
- // but it is flipped upside down so we flip the sprite
- node->getSprite()->setFlippedY(true);
- node->setType( ProgressTimer::Type::BAR);
-
- node->setMidpoint(Vec2(0.5f, 0.5f));
- node->setBarChangeRate(Vec2(1, 1));
-
- node->setPercentage(0);
- node->setPosition(size.width/2, size.height/2);
- node->setAnchorPoint(Vec2(0.5f,0.5f));
-
- return node;
- }
- // TransitionProgressOutIn
- TransitionProgressOutIn* TransitionProgressOutIn::create(float t, Scene* scene)
- {
- TransitionProgressOutIn* newScene = new (std::nothrow) TransitionProgressOutIn();
- if(newScene && newScene->initWithDuration(t, scene))
- {
- newScene->autorelease();
- return newScene;
- }
- CC_SAFE_DELETE(newScene);
- return nullptr;
- }
- ProgressTimer* TransitionProgressOutIn::progressTimerNodeWithRenderTexture(RenderTexture* texture)
- {
- Size size = Director::getInstance()->getWinSize();
-
- ProgressTimer* node = ProgressTimer::create(texture->getSprite());
-
- // but it is flipped upside down so we flip the sprite
- node->getSprite()->setFlippedY(true);
- node->setType( ProgressTimer::Type::BAR );
-
- node->setMidpoint(Vec2(0.5f, 0.5f));
- node->setBarChangeRate(Vec2(1, 1));
-
- node->setPercentage(100);
- node->setPosition(size.width/2, size.height/2);
- node->setAnchorPoint(Vec2(0.5f,0.5f));
-
- return node;
- }
- NS_CC_END
|