CCTransition.js 51 KB

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