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