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