CCTransition.cpp 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756
  1. /****************************************************************************
  2. Copyright (c) 2009-2010 Ricardo Quesada
  3. Copyright (c) 2010-2012 cocos2d-x.org
  4. Copyright (c) 2011 Zynga Inc.
  5. Copyright (c) 2013-2016 Chukong Technologies Inc.
  6. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  7. http://www.cocos2d-x.org
  8. Permission is hereby granted, free of charge, to any person obtaining a copy
  9. of this software and associated documentation files (the "Software"), to deal
  10. in the Software without restriction, including without limitation the rights
  11. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. copies of the Software, and to permit persons to whom the Software is
  13. furnished to do so, subject to the following conditions:
  14. The above copyright notice and this permission notice shall be included in
  15. all copies or substantial portions of the Software.
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. THE SOFTWARE.
  23. ****************************************************************************/
  24. #include "2d/CCTransition.h"
  25. #include "2d/CCActionInterval.h"
  26. #include "2d/CCActionInstant.h"
  27. #include "2d/CCActionEase.h"
  28. #include "2d/CCActionCamera.h"
  29. #include "2d/CCActionTiledGrid.h"
  30. #include "2d/CCActionGrid.h"
  31. #include "2d/CCLayer.h"
  32. #include "2d/CCRenderTexture.h"
  33. #include "2d/CCNodeGrid.h"
  34. #include "base/CCDirector.h"
  35. #include "base/CCEventDispatcher.h"
  36. NS_CC_BEGIN
  37. const unsigned int kSceneFade = 0xFADEFADE;
  38. TransitionScene::TransitionScene()
  39. : _inScene(nullptr)
  40. , _outScene(nullptr)
  41. , _duration(0.0f)
  42. , _isInSceneOnTop(false)
  43. , _isSendCleanupToScene(false)
  44. {
  45. }
  46. TransitionScene::~TransitionScene()
  47. {
  48. CC_SAFE_RELEASE(_inScene);
  49. CC_SAFE_RELEASE(_outScene);
  50. }
  51. TransitionScene * TransitionScene::create(float t, Scene *scene)
  52. {
  53. TransitionScene * pScene = new (std::nothrow) TransitionScene();
  54. if(pScene && pScene->initWithDuration(t,scene))
  55. {
  56. pScene->autorelease();
  57. return pScene;
  58. }
  59. CC_SAFE_DELETE(pScene);
  60. return nullptr;
  61. }
  62. bool TransitionScene::initWithDuration(float t, Scene *scene)
  63. {
  64. CCASSERT(scene != nullptr, "Argument scene must be non-nil");
  65. if (Scene::init())
  66. {
  67. _duration = t;
  68. // retain
  69. #if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
  70. auto sEngine = ScriptEngineManager::getInstance()->getScriptEngine();
  71. if (sEngine)
  72. {
  73. sEngine->retainScriptObject(this, scene);
  74. }
  75. #endif // CC_ENABLE_GC_FOR_NATIVE_OBJECTS
  76. _inScene = scene;
  77. _inScene->retain();
  78. _outScene = Director::getInstance()->getRunningScene();
  79. if (_outScene == nullptr)
  80. {
  81. _outScene = Scene::create();
  82. // just change its state is running that can run actions later
  83. // issue: https://github.com/cocos2d/cocos2d-x/issues/17442
  84. _outScene->onEnter();
  85. }
  86. _outScene->retain();
  87. CCASSERT( _inScene != _outScene, "Incoming scene must be different from the outgoing scene" );
  88. sceneOrder();
  89. return true;
  90. }
  91. else
  92. {
  93. return false;
  94. }
  95. }
  96. void TransitionScene::sceneOrder()
  97. {
  98. _isInSceneOnTop = true;
  99. }
  100. void TransitionScene::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
  101. {
  102. Scene::draw(renderer, transform, flags);
  103. if( _isInSceneOnTop ) {
  104. _outScene->visit(renderer, transform, flags);
  105. _inScene->visit(renderer, transform, flags);
  106. } else {
  107. _inScene->visit(renderer, transform, flags);
  108. _outScene->visit(renderer, transform, flags);
  109. }
  110. }
  111. void TransitionScene::finish()
  112. {
  113. // clean up
  114. _inScene->setVisible(true);
  115. _inScene->setPosition(0,0);
  116. _inScene->setScale(1.0f);
  117. _inScene->setRotation(0.0f);
  118. _inScene->setAdditionalTransform(nullptr);
  119. _outScene->setVisible(false);
  120. _outScene->setPosition(0,0);
  121. _outScene->setScale(1.0f);
  122. _outScene->setRotation(0.0f);
  123. _outScene->setAdditionalTransform(nullptr);
  124. //[self schedule:@selector(setNewScene:) interval:0];
  125. this->schedule(CC_SCHEDULE_SELECTOR(TransitionScene::setNewScene), 0);
  126. }
  127. void TransitionScene::setNewScene(float /*dt*/)
  128. {
  129. this->unschedule(CC_SCHEDULE_SELECTOR(TransitionScene::setNewScene));
  130. // Before replacing, save the "send cleanup to scene"
  131. Director *director = Director::getInstance();
  132. _isSendCleanupToScene = director->isSendCleanupToScene();
  133. director->replaceScene(_inScene);
  134. #if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
  135. auto sEngine = ScriptEngineManager::getInstance()->getScriptEngine();
  136. if (sEngine)
  137. {
  138. sEngine->releaseScriptObject(this, _inScene);
  139. }
  140. #endif // CC_ENABLE_GC_FOR_NATIVE_OBJECTS
  141. // issue #267
  142. _outScene->setVisible(true);
  143. }
  144. void TransitionScene::hideOutShowIn()
  145. {
  146. _inScene->setVisible(true);
  147. _outScene->setVisible(false);
  148. }
  149. // custom onEnter
  150. void TransitionScene::onEnter()
  151. {
  152. #if CC_ENABLE_SCRIPT_BINDING
  153. if (_scriptType == kScriptTypeJavascript)
  154. {
  155. if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter))
  156. return;
  157. }
  158. #endif // #if CC_ENABLE_SCRIPT_BINDING
  159. Scene::onEnter();
  160. // disable events while transitions
  161. _eventDispatcher->setEnabled(false);
  162. // outScene should not receive the onEnter callback
  163. // only the onExitTransitionDidStart
  164. _outScene->onExitTransitionDidStart();
  165. _inScene->onEnter();
  166. }
  167. // custom onExit
  168. void TransitionScene::onExit()
  169. {
  170. #if CC_ENABLE_SCRIPT_BINDING
  171. if (_scriptType == kScriptTypeJavascript)
  172. {
  173. if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnExit))
  174. return;
  175. }
  176. #endif // #if CC_ENABLE_SCRIPT_BINDING
  177. Scene::onExit();
  178. // enable events while transitions
  179. _eventDispatcher->setEnabled(true);
  180. _outScene->onExit();
  181. // _inScene should not receive the onEnter callback
  182. // only the onEnterTransitionDidFinish
  183. _inScene->onEnterTransitionDidFinish();
  184. #if CC_ENABLE_SCRIPT_BINDING
  185. if (ScriptEngineManager::getInstance()->getScriptEngine())
  186. ScriptEngineManager::getInstance()->getScriptEngine()->garbageCollect();
  187. #endif // CC_ENABLE_SCRIPT_BINDING
  188. }
  189. // custom cleanup
  190. void TransitionScene::cleanup()
  191. {
  192. #if CC_ENABLE_SCRIPT_BINDING
  193. if (_scriptType == kScriptTypeJavascript)
  194. {
  195. if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnCleanup))
  196. return;
  197. }
  198. #endif // #if CC_ENABLE_SCRIPT_BINDING
  199. Scene::cleanup();
  200. if( _isSendCleanupToScene )
  201. _outScene->cleanup();
  202. }
  203. //
  204. // Oriented Transition
  205. //
  206. TransitionSceneOriented::TransitionSceneOriented()
  207. {
  208. }
  209. TransitionSceneOriented::~TransitionSceneOriented()
  210. {
  211. }
  212. TransitionSceneOriented * TransitionSceneOriented::create(float t, Scene *scene, Orientation orientation)
  213. {
  214. TransitionSceneOriented * newScene = new (std::nothrow) TransitionSceneOriented();
  215. newScene->initWithDuration(t,scene,orientation);
  216. newScene->autorelease();
  217. return newScene;
  218. }
  219. bool TransitionSceneOriented::initWithDuration(float t, Scene *scene, Orientation orientation)
  220. {
  221. if ( TransitionScene::initWithDuration(t, scene) )
  222. {
  223. _orientation = orientation;
  224. }
  225. return true;
  226. }
  227. //
  228. // RotoZoom
  229. //
  230. TransitionRotoZoom::TransitionRotoZoom()
  231. {
  232. }
  233. TransitionRotoZoom* TransitionRotoZoom::create(float t, Scene* scene)
  234. {
  235. TransitionRotoZoom* newScene = new (std::nothrow) TransitionRotoZoom();
  236. if(newScene && newScene->initWithDuration(t, scene))
  237. {
  238. newScene->autorelease();
  239. return newScene;
  240. }
  241. CC_SAFE_DELETE(newScene);
  242. return nullptr;
  243. }
  244. TransitionRotoZoom::~TransitionRotoZoom()
  245. {
  246. }
  247. void TransitionRotoZoom:: onEnter()
  248. {
  249. TransitionScene::onEnter();
  250. _inScene->setScale(0.001f);
  251. _outScene->setScale(1.0f);
  252. _inScene->setAnchorPoint(Vec2(0.5f, 0.5f));
  253. _outScene->setAnchorPoint(Vec2(0.5f, 0.5f));
  254. auto rotozoom = Sequence::create
  255. (
  256. Spawn::create
  257. (
  258. ScaleBy::create(_duration/2, 0.001f),
  259. RotateBy::create(_duration/2, 360 * 2),
  260. nullptr
  261. ),
  262. DelayTime::create(_duration/2),
  263. nullptr
  264. );
  265. _outScene->runAction(rotozoom);
  266. _inScene->runAction
  267. (
  268. Sequence::create
  269. (
  270. rotozoom->reverse(),
  271. CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
  272. nullptr
  273. )
  274. );
  275. }
  276. //
  277. // JumpZoom
  278. //
  279. TransitionJumpZoom::TransitionJumpZoom()
  280. {
  281. }
  282. TransitionJumpZoom::~TransitionJumpZoom()
  283. {
  284. }
  285. TransitionJumpZoom* TransitionJumpZoom::create(float t, Scene* scene)
  286. {
  287. TransitionJumpZoom* newScene = new (std::nothrow) TransitionJumpZoom();
  288. if(newScene && newScene->initWithDuration(t, scene))
  289. {
  290. newScene->autorelease();
  291. return newScene;
  292. }
  293. CC_SAFE_DELETE(newScene);
  294. return nullptr;
  295. }
  296. void TransitionJumpZoom::onEnter()
  297. {
  298. TransitionScene::onEnter();
  299. Size s = Director::getInstance()->getWinSize();
  300. _inScene->setScale(0.5f);
  301. _inScene->setPosition(s.width, 0);
  302. _inScene->setAnchorPoint(Vec2(0.5f, 0.5f));
  303. _outScene->setAnchorPoint(Vec2(0.5f, 0.5f));
  304. ActionInterval *jump = JumpBy::create(_duration/4, Vec2(-s.width,0), s.width/4, 2);
  305. ActionInterval *scaleIn = ScaleTo::create(_duration/4, 1.0f);
  306. ActionInterval *scaleOut = ScaleTo::create(_duration/4, 0.5f);
  307. auto jumpZoomOut = Sequence::create(scaleOut, jump, nullptr);
  308. auto jumpZoomIn = Sequence::create(jump, scaleIn, nullptr);
  309. ActionInterval *delay = DelayTime::create(_duration/2);
  310. _outScene->runAction(jumpZoomOut);
  311. _inScene->runAction
  312. (
  313. Sequence::create
  314. (
  315. delay,
  316. jumpZoomIn,
  317. CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
  318. nullptr
  319. )
  320. );
  321. }
  322. //
  323. // MoveInL
  324. //
  325. TransitionMoveInL::TransitionMoveInL()
  326. {
  327. }
  328. TransitionMoveInL::~TransitionMoveInL()
  329. {
  330. }
  331. TransitionMoveInL* TransitionMoveInL::create(float t, Scene* scene)
  332. {
  333. TransitionMoveInL* newScene = new (std::nothrow) TransitionMoveInL();
  334. if(newScene && newScene->initWithDuration(t, scene))
  335. {
  336. newScene->autorelease();
  337. return newScene;
  338. }
  339. CC_SAFE_DELETE(newScene);
  340. return nullptr;
  341. }
  342. void TransitionMoveInL::onEnter()
  343. {
  344. TransitionScene::onEnter();
  345. this->initScenes();
  346. ActionInterval *a = this->action();
  347. _inScene->runAction
  348. (
  349. Sequence::create
  350. (
  351. this->easeActionWithAction(a),
  352. CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
  353. nullptr
  354. )
  355. );
  356. }
  357. ActionInterval* TransitionMoveInL::action()
  358. {
  359. return MoveTo::create(_duration, Vec2(0,0));
  360. }
  361. ActionInterval* TransitionMoveInL::easeActionWithAction(ActionInterval* action)
  362. {
  363. return EaseOut::create(action, 2.0f);
  364. // return [EaseElasticOut actionWithAction:action period:0.4f];
  365. }
  366. void TransitionMoveInL::initScenes()
  367. {
  368. Size s = Director::getInstance()->getWinSize();
  369. _inScene->setPosition(-s.width,0);
  370. }
  371. //
  372. // MoveInR
  373. //
  374. TransitionMoveInR::TransitionMoveInR()
  375. {
  376. }
  377. TransitionMoveInR::~TransitionMoveInR()
  378. {
  379. }
  380. TransitionMoveInR* TransitionMoveInR::create(float t, Scene* scene)
  381. {
  382. TransitionMoveInR* newScene = new (std::nothrow) TransitionMoveInR();
  383. if(newScene && newScene->initWithDuration(t, scene))
  384. {
  385. newScene->autorelease();
  386. return newScene;
  387. }
  388. CC_SAFE_DELETE(newScene);
  389. return nullptr;
  390. }
  391. void TransitionMoveInR::initScenes()
  392. {
  393. Size s = Director::getInstance()->getWinSize();
  394. _inScene->setPosition(s.width,0);
  395. }
  396. //
  397. // MoveInT
  398. //
  399. TransitionMoveInT::TransitionMoveInT()
  400. {
  401. }
  402. TransitionMoveInT::~TransitionMoveInT()
  403. {
  404. }
  405. TransitionMoveInT* TransitionMoveInT::create(float t, Scene* scene)
  406. {
  407. TransitionMoveInT* newScene = new (std::nothrow) TransitionMoveInT();
  408. if(newScene && newScene->initWithDuration(t, scene))
  409. {
  410. newScene->autorelease();
  411. return newScene;
  412. }
  413. CC_SAFE_DELETE(newScene);
  414. return nullptr;
  415. }
  416. void TransitionMoveInT::initScenes()
  417. {
  418. Size s = Director::getInstance()->getWinSize();
  419. _inScene->setPosition(0,s.height);
  420. }
  421. //
  422. // MoveInB
  423. //
  424. TransitionMoveInB::TransitionMoveInB()
  425. {
  426. }
  427. TransitionMoveInB::~TransitionMoveInB()
  428. {
  429. }
  430. TransitionMoveInB* TransitionMoveInB::create(float t, Scene* scene)
  431. {
  432. TransitionMoveInB* newScene = new (std::nothrow) TransitionMoveInB();
  433. if(newScene && newScene->initWithDuration(t, scene))
  434. {
  435. newScene->autorelease();
  436. return newScene;
  437. }
  438. CC_SAFE_DELETE(newScene);
  439. return nullptr;
  440. }
  441. void TransitionMoveInB::initScenes()
  442. {
  443. Size s = Director::getInstance()->getWinSize();
  444. _inScene->setPosition(0,-s.height);
  445. }
  446. //
  447. // SlideInL
  448. //
  449. // The adjust factor is needed to prevent issue #442
  450. // One solution is to use DONT_RENDER_IN_SUBPIXELS images, but NO
  451. // The other issue is that in some transitions (and I don't know why)
  452. // the order should be reversed (In in top of Out or vice-versa).
  453. #define ADJUST_FACTOR 0.5f
  454. TransitionSlideInL::TransitionSlideInL()
  455. {
  456. }
  457. TransitionSlideInL::~TransitionSlideInL()
  458. {
  459. }
  460. void TransitionSlideInL::onEnter()
  461. {
  462. TransitionScene::onEnter();
  463. this->initScenes();
  464. ActionInterval *in = this->action();
  465. ActionInterval *out = this->action();
  466. ActionInterval* inAction = easeActionWithAction(in);
  467. ActionInterval* outAction = Sequence::create
  468. (
  469. easeActionWithAction(out),
  470. CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
  471. nullptr
  472. );
  473. _inScene->runAction(inAction);
  474. _outScene->runAction(outAction);
  475. }
  476. void TransitionSlideInL::sceneOrder()
  477. {
  478. _isInSceneOnTop = false;
  479. }
  480. void TransitionSlideInL:: initScenes()
  481. {
  482. Size s = Director::getInstance()->getWinSize();
  483. _inScene->setPosition(-(s.width-ADJUST_FACTOR),0);
  484. }
  485. ActionInterval* TransitionSlideInL::action()
  486. {
  487. Size s = Director::getInstance()->getWinSize();
  488. return MoveBy::create(_duration, Vec2(s.width-ADJUST_FACTOR,0));
  489. }
  490. ActionInterval* TransitionSlideInL::easeActionWithAction(ActionInterval* action)
  491. {
  492. return EaseOut::create(action, 2.0f);
  493. }
  494. TransitionSlideInL* TransitionSlideInL::create(float t, Scene* scene)
  495. {
  496. TransitionSlideInL* newScene = new (std::nothrow) TransitionSlideInL();
  497. if(newScene && newScene->initWithDuration(t, scene))
  498. {
  499. newScene->autorelease();
  500. return newScene;
  501. }
  502. CC_SAFE_DELETE(newScene);
  503. return nullptr;
  504. }
  505. //
  506. // SlideInR
  507. //
  508. TransitionSlideInR::TransitionSlideInR()
  509. {
  510. }
  511. TransitionSlideInR::~TransitionSlideInR()
  512. {
  513. }
  514. TransitionSlideInR* TransitionSlideInR::create(float t, Scene* scene)
  515. {
  516. TransitionSlideInR* newScene = new (std::nothrow) TransitionSlideInR();
  517. if(newScene && newScene->initWithDuration(t, scene))
  518. {
  519. newScene->autorelease();
  520. return newScene;
  521. }
  522. CC_SAFE_DELETE(newScene);
  523. return nullptr;
  524. }
  525. void TransitionSlideInR::sceneOrder()
  526. {
  527. _isInSceneOnTop = true;
  528. }
  529. void TransitionSlideInR::initScenes()
  530. {
  531. Size s = Director::getInstance()->getWinSize();
  532. _inScene->setPosition(s.width-ADJUST_FACTOR,0);
  533. }
  534. ActionInterval* TransitionSlideInR:: action()
  535. {
  536. Size s = Director::getInstance()->getWinSize();
  537. return MoveBy::create(_duration, Vec2(-(s.width-ADJUST_FACTOR),0));
  538. }
  539. //
  540. // SlideInT
  541. //
  542. TransitionSlideInT::TransitionSlideInT()
  543. {
  544. }
  545. TransitionSlideInT::~TransitionSlideInT()
  546. {
  547. }
  548. TransitionSlideInT* TransitionSlideInT::create(float t, Scene* scene)
  549. {
  550. TransitionSlideInT* newScene = new (std::nothrow) TransitionSlideInT();
  551. if(newScene && newScene->initWithDuration(t, scene))
  552. {
  553. newScene->autorelease();
  554. return newScene;
  555. }
  556. CC_SAFE_DELETE(newScene);
  557. return nullptr;
  558. }
  559. void TransitionSlideInT::sceneOrder()
  560. {
  561. _isInSceneOnTop = false;
  562. }
  563. void TransitionSlideInT::initScenes()
  564. {
  565. Size s = Director::getInstance()->getWinSize();
  566. _inScene->setPosition(0,s.height-ADJUST_FACTOR);
  567. }
  568. ActionInterval* TransitionSlideInT::action()
  569. {
  570. Size s = Director::getInstance()->getWinSize();
  571. return MoveBy::create(_duration, Vec2(0,-(s.height-ADJUST_FACTOR)));
  572. }
  573. //
  574. // SlideInB
  575. //
  576. TransitionSlideInB::TransitionSlideInB()
  577. {
  578. }
  579. TransitionSlideInB::~TransitionSlideInB()
  580. {
  581. }
  582. TransitionSlideInB* TransitionSlideInB::create(float t, Scene* scene)
  583. {
  584. TransitionSlideInB* newScene = new (std::nothrow) TransitionSlideInB();
  585. if(newScene && newScene->initWithDuration(t, scene))
  586. {
  587. newScene->autorelease();
  588. return newScene;
  589. }
  590. CC_SAFE_DELETE(newScene);
  591. return nullptr;
  592. }
  593. void TransitionSlideInB::sceneOrder()
  594. {
  595. _isInSceneOnTop = true;
  596. }
  597. void TransitionSlideInB:: initScenes()
  598. {
  599. Size s = Director::getInstance()->getWinSize();
  600. _inScene->setPosition(0,-(s.height-ADJUST_FACTOR));
  601. }
  602. ActionInterval* TransitionSlideInB:: action()
  603. {
  604. Size s = Director::getInstance()->getWinSize();
  605. return MoveBy::create(_duration, Vec2(0,s.height-ADJUST_FACTOR));
  606. }
  607. //
  608. // ShrinkGrow Transition
  609. //
  610. TransitionShrinkGrow::TransitionShrinkGrow()
  611. {
  612. }
  613. TransitionShrinkGrow::~TransitionShrinkGrow()
  614. {
  615. }
  616. TransitionShrinkGrow* TransitionShrinkGrow::create(float t, Scene* scene)
  617. {
  618. TransitionShrinkGrow* newScene = new (std::nothrow) TransitionShrinkGrow();
  619. if(newScene && newScene->initWithDuration(t, scene))
  620. {
  621. newScene->autorelease();
  622. return newScene;
  623. }
  624. CC_SAFE_DELETE(newScene);
  625. return nullptr;
  626. }
  627. void TransitionShrinkGrow::onEnter()
  628. {
  629. TransitionScene::onEnter();
  630. _inScene->setScale(0.001f);
  631. _outScene->setScale(1.0f);
  632. _inScene->setAnchorPoint(Vec2(2/3.0f,0.5f));
  633. _outScene->setAnchorPoint(Vec2(1/3.0f,0.5f));
  634. ActionInterval* scaleOut = ScaleTo::create(_duration, 0.01f);
  635. ActionInterval* scaleIn = ScaleTo::create(_duration, 1.0f);
  636. _inScene->runAction(this->easeActionWithAction(scaleIn));
  637. _outScene->runAction
  638. (
  639. Sequence::create
  640. (
  641. this->easeActionWithAction(scaleOut),
  642. CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
  643. nullptr
  644. )
  645. );
  646. }
  647. ActionInterval* TransitionShrinkGrow:: easeActionWithAction(ActionInterval* action)
  648. {
  649. return EaseOut::create(action, 2.0f);
  650. // return [EaseElasticOut actionWithAction:action period:0.3f];
  651. }
  652. //
  653. // FlipX Transition
  654. //
  655. TransitionFlipX::TransitionFlipX()
  656. {
  657. }
  658. TransitionFlipX::~TransitionFlipX()
  659. {
  660. }
  661. void TransitionFlipX::onEnter()
  662. {
  663. TransitionSceneOriented::onEnter();
  664. _inScene->setVisible(false);
  665. float inDeltaZ, inAngleZ;
  666. float outDeltaZ, outAngleZ;
  667. if( _orientation == TransitionScene::Orientation::RIGHT_OVER )
  668. {
  669. inDeltaZ = 90;
  670. inAngleZ = 270;
  671. outDeltaZ = 90;
  672. outAngleZ = 0;
  673. }
  674. else
  675. {
  676. inDeltaZ = -90;
  677. inAngleZ = 90;
  678. outDeltaZ = -90;
  679. outAngleZ = 0;
  680. }
  681. auto inA = Sequence::create
  682. (
  683. DelayTime::create(_duration/2),
  684. Show::create(),
  685. OrbitCamera::create(_duration/2, 1, 0, inAngleZ, inDeltaZ, 0, 0),
  686. CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
  687. nullptr
  688. );
  689. auto outA = Sequence::create
  690. (
  691. OrbitCamera::create(_duration/2, 1, 0, outAngleZ, outDeltaZ, 0, 0),
  692. Hide::create(),
  693. DelayTime::create(_duration/2),
  694. nullptr
  695. );
  696. _inScene->runAction(inA);
  697. _outScene->runAction(outA);
  698. }
  699. TransitionFlipX* TransitionFlipX::create(float t, Scene* s, Orientation o)
  700. {
  701. TransitionFlipX* newScene = new (std::nothrow) TransitionFlipX();
  702. newScene->initWithDuration(t, s, o);
  703. newScene->autorelease();
  704. return newScene;
  705. }
  706. TransitionFlipX* TransitionFlipX::create(float t, Scene* s)
  707. {
  708. return TransitionFlipX::create(t, s, TransitionScene::Orientation::RIGHT_OVER);
  709. }
  710. //
  711. // FlipY Transition
  712. //
  713. TransitionFlipY::TransitionFlipY()
  714. {
  715. }
  716. TransitionFlipY::~TransitionFlipY()
  717. {
  718. }
  719. void TransitionFlipY::onEnter()
  720. {
  721. TransitionSceneOriented::onEnter();
  722. _inScene->setVisible(false);
  723. float inDeltaZ, inAngleZ;
  724. float outDeltaZ, outAngleZ;
  725. if( _orientation == TransitionScene::Orientation::UP_OVER )
  726. {
  727. inDeltaZ = 90;
  728. inAngleZ = 270;
  729. outDeltaZ = 90;
  730. outAngleZ = 0;
  731. }
  732. else
  733. {
  734. inDeltaZ = -90;
  735. inAngleZ = 90;
  736. outDeltaZ = -90;
  737. outAngleZ = 0;
  738. }
  739. auto inA = Sequence::create
  740. (
  741. DelayTime::create(_duration/2),
  742. Show::create(),
  743. OrbitCamera::create(_duration/2, 1, 0, inAngleZ, inDeltaZ, 90, 0),
  744. CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
  745. nullptr
  746. );
  747. auto outA = Sequence::create
  748. (
  749. OrbitCamera::create(_duration/2, 1, 0, outAngleZ, outDeltaZ, 90, 0),
  750. Hide::create(),
  751. DelayTime::create(_duration/2),
  752. nullptr
  753. );
  754. _inScene->runAction(inA);
  755. _outScene->runAction(outA);
  756. }
  757. TransitionFlipY* TransitionFlipY::create(float t, Scene* s, Orientation o)
  758. {
  759. TransitionFlipY* newScene = new (std::nothrow) TransitionFlipY();
  760. newScene->initWithDuration(t, s, o);
  761. newScene->autorelease();
  762. return newScene;
  763. }
  764. TransitionFlipY* TransitionFlipY::create(float t, Scene* s)
  765. {
  766. return TransitionFlipY::create(t, s, TransitionScene::Orientation::UP_OVER);
  767. }
  768. //
  769. // FlipAngular Transition
  770. //
  771. TransitionFlipAngular::TransitionFlipAngular()
  772. {
  773. }
  774. TransitionFlipAngular::~TransitionFlipAngular()
  775. {
  776. }
  777. void TransitionFlipAngular::onEnter()
  778. {
  779. TransitionSceneOriented::onEnter();
  780. _inScene->setVisible(false);
  781. float inDeltaZ, inAngleZ;
  782. float outDeltaZ, outAngleZ;
  783. if( _orientation == TransitionScene::Orientation::RIGHT_OVER )
  784. {
  785. inDeltaZ = 90;
  786. inAngleZ = 270;
  787. outDeltaZ = 90;
  788. outAngleZ = 0;
  789. }
  790. else
  791. {
  792. inDeltaZ = -90;
  793. inAngleZ = 90;
  794. outDeltaZ = -90;
  795. outAngleZ = 0;
  796. }
  797. auto inA = Sequence::create
  798. (
  799. DelayTime::create(_duration/2),
  800. Show::create(),
  801. OrbitCamera::create(_duration/2, 1, 0, inAngleZ, inDeltaZ, -45, 0),
  802. CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
  803. nullptr
  804. );
  805. auto outA = Sequence::create
  806. (
  807. OrbitCamera::create(_duration/2, 1, 0, outAngleZ, outDeltaZ, 45, 0),
  808. Hide::create(),
  809. DelayTime::create(_duration/2),
  810. nullptr
  811. );
  812. _inScene->runAction(inA);
  813. _outScene->runAction(outA);
  814. }
  815. TransitionFlipAngular* TransitionFlipAngular::create(float t, Scene* s, Orientation o)
  816. {
  817. TransitionFlipAngular* newScene = new (std::nothrow) TransitionFlipAngular();
  818. newScene->initWithDuration(t, s, o);
  819. newScene->autorelease();
  820. return newScene;
  821. }
  822. TransitionFlipAngular* TransitionFlipAngular::create(float t, Scene* s)
  823. {
  824. return TransitionFlipAngular::create(t, s, TransitionScene::Orientation::RIGHT_OVER);
  825. }
  826. //
  827. // ZoomFlipX Transition
  828. //
  829. TransitionZoomFlipX::TransitionZoomFlipX()
  830. {
  831. }
  832. TransitionZoomFlipX::~TransitionZoomFlipX()
  833. {
  834. }
  835. void TransitionZoomFlipX::onEnter()
  836. {
  837. TransitionSceneOriented::onEnter();
  838. _inScene->setVisible(false);
  839. float inDeltaZ, inAngleZ;
  840. float outDeltaZ, outAngleZ;
  841. if( _orientation == TransitionScene::Orientation::RIGHT_OVER ) {
  842. inDeltaZ = 90;
  843. inAngleZ = 270;
  844. outDeltaZ = 90;
  845. outAngleZ = 0;
  846. }
  847. else
  848. {
  849. inDeltaZ = -90;
  850. inAngleZ = 90;
  851. outDeltaZ = -90;
  852. outAngleZ = 0;
  853. }
  854. auto inA = Sequence::create
  855. (
  856. DelayTime::create(_duration/2),
  857. Spawn::create
  858. (
  859. OrbitCamera::create(_duration/2, 1, 0, inAngleZ, inDeltaZ, 0, 0),
  860. ScaleTo::create(_duration/2, 1),
  861. Show::create(),
  862. nullptr
  863. ),
  864. CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
  865. nullptr
  866. );
  867. auto outA = Sequence::create
  868. (
  869. Spawn::create
  870. (
  871. OrbitCamera::create(_duration/2, 1, 0, outAngleZ, outDeltaZ, 0, 0),
  872. ScaleTo::create(_duration/2, 0.5f),
  873. nullptr
  874. ),
  875. Hide::create(),
  876. DelayTime::create(_duration/2),
  877. nullptr
  878. );
  879. _inScene->setScale(0.5f);
  880. _inScene->runAction(inA);
  881. _outScene->runAction(outA);
  882. }
  883. TransitionZoomFlipX* TransitionZoomFlipX::create(float t, Scene* s, Orientation o)
  884. {
  885. TransitionZoomFlipX* newScene = new (std::nothrow) TransitionZoomFlipX();
  886. newScene->initWithDuration(t, s, o);
  887. newScene->autorelease();
  888. return newScene;
  889. }
  890. TransitionZoomFlipX* TransitionZoomFlipX::create(float t, Scene* s)
  891. {
  892. return TransitionZoomFlipX::create(t, s, TransitionScene::Orientation::RIGHT_OVER);
  893. }
  894. //
  895. // ZoomFlipY Transition
  896. //
  897. TransitionZoomFlipY::TransitionZoomFlipY()
  898. {
  899. }
  900. TransitionZoomFlipY::~TransitionZoomFlipY()
  901. {
  902. }
  903. void TransitionZoomFlipY::onEnter()
  904. {
  905. TransitionSceneOriented::onEnter();
  906. _inScene->setVisible(false);
  907. float inDeltaZ, inAngleZ;
  908. float outDeltaZ, outAngleZ;
  909. if( _orientation== TransitionScene::Orientation::UP_OVER ) {
  910. inDeltaZ = 90;
  911. inAngleZ = 270;
  912. outDeltaZ = 90;
  913. outAngleZ = 0;
  914. } else {
  915. inDeltaZ = -90;
  916. inAngleZ = 90;
  917. outDeltaZ = -90;
  918. outAngleZ = 0;
  919. }
  920. auto inA = Sequence::create
  921. (
  922. DelayTime::create(_duration/2),
  923. Spawn::create
  924. (
  925. OrbitCamera::create(_duration/2, 1, 0, inAngleZ, inDeltaZ, 90, 0),
  926. ScaleTo::create(_duration/2, 1),
  927. Show::create(),
  928. nullptr
  929. ),
  930. CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
  931. nullptr
  932. );
  933. auto outA = Sequence::create
  934. (
  935. Spawn::create
  936. (
  937. OrbitCamera::create(_duration/2, 1, 0, outAngleZ, outDeltaZ, 90, 0),
  938. ScaleTo::create(_duration/2, 0.5f),
  939. nullptr
  940. ),
  941. Hide::create(),
  942. DelayTime::create(_duration/2),
  943. nullptr
  944. );
  945. _inScene->setScale(0.5f);
  946. _inScene->runAction(inA);
  947. _outScene->runAction(outA);
  948. }
  949. TransitionZoomFlipY* TransitionZoomFlipY::create(float t, Scene* s, Orientation o)
  950. {
  951. TransitionZoomFlipY* newScene = new (std::nothrow) TransitionZoomFlipY();
  952. newScene->initWithDuration(t, s, o);
  953. newScene->autorelease();
  954. return newScene;
  955. }
  956. TransitionZoomFlipY* TransitionZoomFlipY::create(float t, Scene* s)
  957. {
  958. return TransitionZoomFlipY::create(t, s, TransitionScene::Orientation::UP_OVER);
  959. }
  960. //
  961. // ZoomFlipAngular Transition
  962. //
  963. TransitionZoomFlipAngular::TransitionZoomFlipAngular()
  964. {
  965. }
  966. TransitionZoomFlipAngular::~TransitionZoomFlipAngular()
  967. {
  968. }
  969. void TransitionZoomFlipAngular::onEnter()
  970. {
  971. TransitionSceneOriented::onEnter();
  972. _inScene->setVisible(false);
  973. float inDeltaZ, inAngleZ;
  974. float outDeltaZ, outAngleZ;
  975. if( _orientation == TransitionScene::Orientation::RIGHT_OVER ) {
  976. inDeltaZ = 90;
  977. inAngleZ = 270;
  978. outDeltaZ = 90;
  979. outAngleZ = 0;
  980. }
  981. else
  982. {
  983. inDeltaZ = -90;
  984. inAngleZ = 90;
  985. outDeltaZ = -90;
  986. outAngleZ = 0;
  987. }
  988. auto inA = Sequence::create
  989. (
  990. DelayTime::create(_duration/2),
  991. Spawn::create
  992. (
  993. OrbitCamera::create(_duration/2, 1, 0, inAngleZ, inDeltaZ, -45, 0),
  994. ScaleTo::create(_duration/2, 1),
  995. Show::create(),
  996. nullptr
  997. ),
  998. Show::create(),
  999. CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
  1000. nullptr
  1001. );
  1002. auto outA = Sequence::create
  1003. (
  1004. Spawn::create
  1005. (
  1006. OrbitCamera::create(_duration/2, 1, 0 , outAngleZ, outDeltaZ, 45, 0),
  1007. ScaleTo::create(_duration/2, 0.5f),
  1008. nullptr
  1009. ),
  1010. Hide::create(),
  1011. DelayTime::create(_duration/2),
  1012. nullptr
  1013. );
  1014. _inScene->setScale(0.5f);
  1015. _inScene->runAction(inA);
  1016. _outScene->runAction(outA);
  1017. }
  1018. TransitionZoomFlipAngular* TransitionZoomFlipAngular::create(float t, Scene* s, Orientation o)
  1019. {
  1020. TransitionZoomFlipAngular* newScene = new (std::nothrow) TransitionZoomFlipAngular();
  1021. newScene->initWithDuration(t, s, o);
  1022. newScene->autorelease();
  1023. return newScene;
  1024. }
  1025. TransitionZoomFlipAngular* TransitionZoomFlipAngular::create(float t, Scene* s)
  1026. {
  1027. return TransitionZoomFlipAngular::create(t, s, TransitionScene::Orientation::RIGHT_OVER);
  1028. }
  1029. //
  1030. // Fade Transition
  1031. //
  1032. TransitionFade::TransitionFade()
  1033. {
  1034. }
  1035. TransitionFade::~TransitionFade()
  1036. {
  1037. }
  1038. TransitionFade * TransitionFade::create(float duration, Scene *scene, const Color3B& color)
  1039. {
  1040. TransitionFade * transition = new (std::nothrow) TransitionFade();
  1041. transition->initWithDuration(duration, scene, color);
  1042. transition->autorelease();
  1043. return transition;
  1044. }
  1045. TransitionFade* TransitionFade::create(float duration,Scene* scene)
  1046. {
  1047. return TransitionFade::create(duration, scene, Color3B::BLACK);
  1048. }
  1049. bool TransitionFade::initWithDuration(float duration, Scene *scene, const Color3B& color)
  1050. {
  1051. if (TransitionScene::initWithDuration(duration, scene))
  1052. {
  1053. _color.r = color.r;
  1054. _color.g = color.g;
  1055. _color.b = color.b;
  1056. _color.a = 0;
  1057. }
  1058. return true;
  1059. }
  1060. bool TransitionFade::initWithDuration(float t, Scene *scene)
  1061. {
  1062. this->initWithDuration(t, scene, Color3B::BLACK);
  1063. return true;
  1064. }
  1065. void TransitionFade :: onEnter()
  1066. {
  1067. TransitionScene::onEnter();
  1068. LayerColor* l = LayerColor::create(_color);
  1069. _inScene->setVisible(false);
  1070. addChild(l, 2, kSceneFade);
  1071. Node* f = getChildByTag(kSceneFade);
  1072. auto a = Sequence::create
  1073. (
  1074. FadeIn::create(_duration/2),
  1075. CallFunc::create(CC_CALLBACK_0(TransitionScene::hideOutShowIn,this)),
  1076. FadeOut::create(_duration/2),
  1077. CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
  1078. nullptr
  1079. );
  1080. f->runAction(a);
  1081. }
  1082. void TransitionFade::onExit()
  1083. {
  1084. TransitionScene::onExit();
  1085. this->removeChildByTag(kSceneFade, false);
  1086. }
  1087. //
  1088. // Cross Fade Transition
  1089. //
  1090. TransitionCrossFade::TransitionCrossFade()
  1091. {
  1092. }
  1093. TransitionCrossFade::~TransitionCrossFade()
  1094. {
  1095. }
  1096. TransitionCrossFade* TransitionCrossFade::create(float t, Scene* scene)
  1097. {
  1098. TransitionCrossFade* newScene = new (std::nothrow) TransitionCrossFade();
  1099. if(newScene && newScene->initWithDuration(t, scene))
  1100. {
  1101. newScene->autorelease();
  1102. return newScene;
  1103. }
  1104. CC_SAFE_DELETE(newScene);
  1105. return nullptr;
  1106. }
  1107. void TransitionCrossFade::draw(Renderer* /*renderer*/, const Mat4 &/*transform*/, uint32_t /*flags*/)
  1108. {
  1109. // override draw since both scenes (textures) are rendered in 1 scene
  1110. }
  1111. void TransitionCrossFade::onEnter()
  1112. {
  1113. TransitionScene::onEnter();
  1114. // create a transparent color layer
  1115. // in which we are going to add our rendertextures
  1116. Color4B color(0,0,0,0);
  1117. Size size = Director::getInstance()->getWinSize();
  1118. LayerColor* layer = LayerColor::create(color);
  1119. // create the first render texture for inScene
  1120. RenderTexture* inTexture = RenderTexture::create((int)size.width, (int)size.height,Texture2D::PixelFormat::RGBA8888,GL_DEPTH24_STENCIL8);
  1121. if (nullptr == inTexture)
  1122. {
  1123. return;
  1124. }
  1125. inTexture->getSprite()->setAnchorPoint( Vec2(0.5f,0.5f) );
  1126. inTexture->setPosition(size.width/2, size.height/2);
  1127. inTexture->setAnchorPoint( Vec2(0.5f,0.5f) );
  1128. // render inScene to its texturebuffer
  1129. inTexture->begin();
  1130. _inScene->visit();
  1131. inTexture->end();
  1132. // create the second render texture for outScene
  1133. RenderTexture* outTexture = RenderTexture::create((int)size.width, (int)size.height,Texture2D::PixelFormat::RGBA8888,GL_DEPTH24_STENCIL8);
  1134. outTexture->getSprite()->setAnchorPoint( Vec2(0.5f,0.5f) );
  1135. outTexture->setPosition(size.width/2, size.height/2);
  1136. outTexture->setAnchorPoint( Vec2(0.5f,0.5f) );
  1137. // render outScene to its texturebuffer
  1138. outTexture->begin();
  1139. _outScene->visit();
  1140. outTexture->end();
  1141. // create blend functions
  1142. // set blendfunctions
  1143. inTexture->getSprite()->setBlendFunc(BlendFunc::DISABLE);
  1144. outTexture->getSprite()->setBlendFunc(BlendFunc::ALPHA_PREMULTIPLIED);
  1145. // add render textures to the layer
  1146. layer->addChild(inTexture);
  1147. layer->addChild(outTexture);
  1148. // initial opacity:
  1149. inTexture->getSprite()->setOpacity(255);
  1150. outTexture->getSprite()->setOpacity(255);
  1151. // create the blend action
  1152. Action* layerAction = Sequence::create
  1153. (
  1154. FadeTo::create(_duration, 0),
  1155. CallFunc::create(CC_CALLBACK_0(TransitionScene::hideOutShowIn,this)),
  1156. CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
  1157. nullptr
  1158. );
  1159. // run the blend action
  1160. outTexture->getSprite()->runAction( layerAction );
  1161. // add the layer (which contains our two rendertextures) to the scene
  1162. addChild(layer, 2, kSceneFade);
  1163. }
  1164. // clean up on exit
  1165. void TransitionCrossFade::onExit()
  1166. {
  1167. // remove our layer and release all containing objects
  1168. this->removeChildByTag(kSceneFade, false);
  1169. TransitionScene::onExit();
  1170. }
  1171. //
  1172. // TurnOffTilesTransition
  1173. //
  1174. TransitionTurnOffTiles::TransitionTurnOffTiles()
  1175. {
  1176. _outSceneProxy = NodeGrid::create();
  1177. _outSceneProxy->retain();
  1178. }
  1179. TransitionTurnOffTiles::~TransitionTurnOffTiles()
  1180. {
  1181. CC_SAFE_RELEASE(_outSceneProxy);
  1182. }
  1183. TransitionTurnOffTiles* TransitionTurnOffTiles::create(float t, Scene* scene)
  1184. {
  1185. TransitionTurnOffTiles* newScene = new (std::nothrow) TransitionTurnOffTiles();
  1186. if(newScene && newScene->initWithDuration(t, scene))
  1187. {
  1188. newScene->autorelease();
  1189. return newScene;
  1190. }
  1191. CC_SAFE_DELETE(newScene);
  1192. return nullptr;
  1193. }
  1194. // override addScenes, and change the order
  1195. void TransitionTurnOffTiles::sceneOrder()
  1196. {
  1197. _isInSceneOnTop = false;
  1198. }
  1199. void TransitionTurnOffTiles::onEnter()
  1200. {
  1201. TransitionScene::onEnter();
  1202. _outSceneProxy->setTarget(_outScene);
  1203. _outSceneProxy->onEnter();
  1204. Size s = Director::getInstance()->getWinSize();
  1205. float aspect = s.width / s.height;
  1206. int x = (int)(12 * aspect);
  1207. int y = 12;
  1208. TurnOffTiles* toff = TurnOffTiles::create(_duration, Size(x,y));
  1209. ActionInterval* action = easeActionWithAction(toff);
  1210. _outSceneProxy->runAction
  1211. (
  1212. Sequence::create
  1213. (
  1214. action,
  1215. CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
  1216. StopGrid::create(),
  1217. nullptr
  1218. )
  1219. );
  1220. }
  1221. void TransitionTurnOffTiles::onExit()
  1222. {
  1223. _outSceneProxy->setTarget(nullptr);
  1224. _outSceneProxy->onExit();
  1225. TransitionScene::onExit();
  1226. }
  1227. void TransitionTurnOffTiles::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
  1228. {
  1229. Scene::draw(renderer, transform, flags);
  1230. if( _isInSceneOnTop )
  1231. {
  1232. _outSceneProxy->visit(renderer, transform, flags);
  1233. _inScene->visit(renderer, transform, flags);
  1234. }
  1235. else
  1236. {
  1237. _inScene->visit(renderer, transform, flags);
  1238. _outSceneProxy->visit(renderer, transform, flags);
  1239. }
  1240. }
  1241. ActionInterval* TransitionTurnOffTiles:: easeActionWithAction(ActionInterval* action)
  1242. {
  1243. return action;
  1244. }
  1245. //
  1246. // SplitCols Transition
  1247. //
  1248. TransitionSplitCols::TransitionSplitCols()
  1249. {
  1250. _gridProxy = NodeGrid::create();
  1251. _gridProxy->retain();
  1252. }
  1253. TransitionSplitCols::~TransitionSplitCols()
  1254. {
  1255. CC_SAFE_RELEASE(_gridProxy);
  1256. }
  1257. TransitionSplitCols* TransitionSplitCols::create(float t, Scene* scene)
  1258. {
  1259. TransitionSplitCols* newScene = new (std::nothrow) TransitionSplitCols();
  1260. if(newScene && newScene->initWithDuration(t, scene))
  1261. {
  1262. newScene->autorelease();
  1263. return newScene;
  1264. }
  1265. CC_SAFE_DELETE(newScene);
  1266. return nullptr;
  1267. }
  1268. void TransitionSplitCols::onEnter()
  1269. {
  1270. TransitionScene::onEnter();
  1271. _gridProxy->setTarget(_outScene);
  1272. _gridProxy->onEnter();
  1273. ActionInterval* split = action();
  1274. auto seq = Sequence::create
  1275. (
  1276. split,
  1277. CallFunc::create(CC_CALLBACK_0(TransitionSplitCols::switchTargetToInscene,this)),
  1278. split->reverse(),
  1279. nullptr
  1280. );
  1281. _gridProxy->runAction
  1282. (
  1283. Sequence::create
  1284. (
  1285. easeActionWithAction(seq),
  1286. CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
  1287. StopGrid::create(),
  1288. nullptr
  1289. )
  1290. );
  1291. }
  1292. void TransitionSplitCols::switchTargetToInscene()
  1293. {
  1294. _gridProxy->setTarget(_inScene);
  1295. }
  1296. void TransitionSplitCols::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
  1297. {
  1298. Scene::draw(renderer, transform, flags);
  1299. _gridProxy->visit(renderer, transform, flags);
  1300. }
  1301. void TransitionSplitCols::onExit()
  1302. {
  1303. _gridProxy->setTarget(nullptr);
  1304. _gridProxy->onExit();
  1305. TransitionScene::onExit();
  1306. }
  1307. ActionInterval* TransitionSplitCols:: action()
  1308. {
  1309. return SplitCols::create(_duration/2.0f, 3);
  1310. }
  1311. ActionInterval* TransitionSplitCols::easeActionWithAction(ActionInterval * action)
  1312. {
  1313. return EaseInOut::create(action, 3.0f);
  1314. }
  1315. //
  1316. // SplitRows Transition
  1317. //
  1318. TransitionSplitRows::TransitionSplitRows()
  1319. {
  1320. }
  1321. TransitionSplitRows::~TransitionSplitRows()
  1322. {
  1323. }
  1324. ActionInterval* TransitionSplitRows::action()
  1325. {
  1326. return SplitRows::create(_duration/2.0f, 3);
  1327. }
  1328. TransitionSplitRows* TransitionSplitRows::create(float t, Scene* scene)
  1329. {
  1330. TransitionSplitRows* newScene = new (std::nothrow) TransitionSplitRows();
  1331. if(newScene && newScene->initWithDuration(t, scene))
  1332. {
  1333. newScene->autorelease();
  1334. return newScene;
  1335. }
  1336. CC_SAFE_DELETE(newScene);
  1337. return nullptr;
  1338. }
  1339. //
  1340. // FadeTR Transition
  1341. //
  1342. TransitionFadeTR::TransitionFadeTR()
  1343. {
  1344. _outSceneProxy = NodeGrid::create();
  1345. _outSceneProxy->retain();
  1346. }
  1347. TransitionFadeTR::~TransitionFadeTR()
  1348. {
  1349. CC_SAFE_RELEASE(_outSceneProxy);
  1350. }
  1351. TransitionFadeTR* TransitionFadeTR::create(float t, Scene* scene)
  1352. {
  1353. TransitionFadeTR* newScene = new (std::nothrow) TransitionFadeTR();
  1354. if(newScene && newScene->initWithDuration(t, scene))
  1355. {
  1356. newScene->autorelease();
  1357. return newScene;
  1358. }
  1359. CC_SAFE_DELETE(newScene);
  1360. return nullptr;
  1361. }
  1362. void TransitionFadeTR::sceneOrder()
  1363. {
  1364. _isInSceneOnTop = false;
  1365. }
  1366. void TransitionFadeTR::onEnter()
  1367. {
  1368. TransitionScene::onEnter();
  1369. _outSceneProxy->setTarget(_outScene);
  1370. _outSceneProxy->onEnter();
  1371. Size s = Director::getInstance()->getWinSize();
  1372. float aspect = s.width / s.height;
  1373. int x = (int)(12 * aspect);
  1374. int y = 12;
  1375. ActionInterval* action = actionWithSize(Size(x,y));
  1376. _outSceneProxy->runAction
  1377. (
  1378. Sequence::create
  1379. (
  1380. easeActionWithAction(action),
  1381. CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
  1382. StopGrid::create(),
  1383. nullptr
  1384. )
  1385. );
  1386. }
  1387. void TransitionFadeTR::onExit()
  1388. {
  1389. _outSceneProxy->setTarget(nullptr);
  1390. _outSceneProxy->onExit();
  1391. TransitionScene::onExit();
  1392. }
  1393. void TransitionFadeTR::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
  1394. {
  1395. Scene::draw(renderer, transform, flags);
  1396. if( _isInSceneOnTop )
  1397. {
  1398. _outSceneProxy->visit(renderer, transform, flags);
  1399. _inScene->visit(renderer, transform, flags);
  1400. }
  1401. else
  1402. {
  1403. _inScene->visit(renderer, transform, flags);
  1404. _outSceneProxy->visit(renderer, transform, flags);
  1405. }
  1406. }
  1407. ActionInterval* TransitionFadeTR::actionWithSize(const Size& size)
  1408. {
  1409. return FadeOutTRTiles::create(_duration, size);
  1410. }
  1411. ActionInterval* TransitionFadeTR:: easeActionWithAction(ActionInterval* action)
  1412. {
  1413. return action;
  1414. }
  1415. //
  1416. // FadeBL Transition
  1417. //
  1418. TransitionFadeBL::TransitionFadeBL()
  1419. {
  1420. }
  1421. TransitionFadeBL::~TransitionFadeBL()
  1422. {
  1423. }
  1424. TransitionFadeBL* TransitionFadeBL::create(float t, Scene* scene)
  1425. {
  1426. TransitionFadeBL* newScene = new (std::nothrow) TransitionFadeBL();
  1427. if(newScene && newScene->initWithDuration(t, scene))
  1428. {
  1429. newScene->autorelease();
  1430. return newScene;
  1431. }
  1432. CC_SAFE_DELETE(newScene);
  1433. return nullptr;
  1434. }
  1435. ActionInterval* TransitionFadeBL::actionWithSize(const Size& size)
  1436. {
  1437. return FadeOutBLTiles::create(_duration, size);
  1438. }
  1439. //
  1440. // FadeUp Transition
  1441. //
  1442. TransitionFadeUp::TransitionFadeUp()
  1443. {
  1444. }
  1445. TransitionFadeUp::~TransitionFadeUp()
  1446. {
  1447. }
  1448. TransitionFadeUp* TransitionFadeUp::create(float t, Scene* scene)
  1449. {
  1450. TransitionFadeUp* newScene = new (std::nothrow) TransitionFadeUp();
  1451. if(newScene && newScene->initWithDuration(t, scene))
  1452. {
  1453. newScene->autorelease();
  1454. return newScene;
  1455. }
  1456. CC_SAFE_DELETE(newScene);
  1457. return nullptr;
  1458. }
  1459. ActionInterval* TransitionFadeUp::actionWithSize(const Size& size)
  1460. {
  1461. return FadeOutUpTiles::create(_duration, size);
  1462. }
  1463. //
  1464. // FadeDown Transition
  1465. //
  1466. TransitionFadeDown::TransitionFadeDown()
  1467. {
  1468. }
  1469. TransitionFadeDown::~TransitionFadeDown()
  1470. {
  1471. }
  1472. TransitionFadeDown* TransitionFadeDown::create(float t, Scene* scene)
  1473. {
  1474. TransitionFadeDown* newScene = new (std::nothrow) TransitionFadeDown();
  1475. if(newScene && newScene->initWithDuration(t, scene))
  1476. {
  1477. newScene->autorelease();
  1478. return newScene;
  1479. }
  1480. CC_SAFE_DELETE(newScene);
  1481. return nullptr;
  1482. }
  1483. ActionInterval* TransitionFadeDown::actionWithSize(const Size& size)
  1484. {
  1485. return FadeOutDownTiles::create(_duration, size);
  1486. }
  1487. NS_CC_END