1 /****************************************************************************
  2  Copyright (c) 2008-2010 Ricardo Quesada
  3  Copyright (c) 2011-2012 cocos2d-x.org
  4  Copyright (c) 2013-2014 Chukong Technologies 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 /**
 28  *<p> A transition which peels back the bottom right hand corner of a scene<br/>
 29  * to transition to the scene beneath it simulating a page turn.<br/></p>
 30  *
 31  * <p>This uses a 3DAction so it's strongly recommended that depth buffering<br/>
 32  * is turned on in cc.director using:</p>
 33  *
 34  * <p>cc.director.setDepthBufferFormat(kDepthBuffer16);</p>
 35  * @class
 36  * @extends cc.TransitionScene
 37  * @param {Number} t time in seconds
 38  * @param {cc.Scene} scene
 39  * @param {Boolean} backwards
 40  * @example
 41  * var trans = new cc.TransitionPageTurn(t, scene, backwards);
 42  */
 43 cc.TransitionPageTurn = cc.TransitionScene.extend(/** @lends cc.TransitionPageTurn# */{
 44 
 45     /**
 46      * @param {Number} t time in seconds
 47      * @param {cc.Scene} scene
 48      * @param {Boolean} backwards
 49      */
 50     ctor:function (t, scene, backwards) {
 51         cc.TransitionScene.prototype.ctor.call(this);
 52         this.initWithDuration(t, scene, backwards);
 53     },
 54 
 55     /**
 56      * @type Boolean
 57      */
 58     _back:true,
 59     _className:"TransitionPageTurn",
 60 
 61     /**
 62      * Creates a base transition with duration and incoming scene.<br/>
 63      * If back is true then the effect is reversed to appear as if the incoming<br/>
 64      * scene is being turned from left over the outgoing scene.
 65      * @param {Number} t time in seconds
 66      * @param {cc.Scene} scene
 67      * @param {Boolean} backwards
 68      * @return {Boolean}
 69      */
 70     initWithDuration:function (t, scene, backwards) {
 71         // XXX: needed before [super init]
 72         this._back = backwards;
 73 
 74         if (cc.TransitionScene.prototype.initWithDuration.call(this, t, scene)) {
 75             // do something
 76         }
 77         return true;
 78     },
 79 
 80     /**
 81      * @param {cc.Size} vector
 82      * @return {cc.ReverseTime|cc.TransitionScene}
 83      */
 84     actionWithSize:function (vector) {
 85         if (this._back)
 86             return cc.reverseTime(cc.pageTurn3D(this._duration, vector));        // Get hold of the PageTurn3DAction
 87         else
 88             return cc.pageTurn3D(this._duration, vector);     // Get hold of the PageTurn3DAction
 89     },
 90 
 91     /**
 92      * custom on enter
 93      */
 94     onEnter:function () {
 95         cc.TransitionScene.prototype.onEnter.call(this);
 96         var winSize = cc.director.getWinSize();
 97         var x, y;
 98         if (winSize.width > winSize.height) {
 99             x = 16;
100             y = 12;
101         } else {
102             x = 12;
103             y = 16;
104         }
105 
106         var action = this.actionWithSize(cc.size(x, y));
107 
108         if (!this._back) {
109             this._outScene.runAction( cc.sequence(action,cc.CallFunc.create(this.finish, this),cc.StopGrid.create()));
110         } else {
111             // to prevent initial flicker
112             this._inScene.visible = false;
113             this._inScene.runAction(
114                 cc.sequence(cc.show(),action, cc.callFunc(this.finish, this), cc.stopGrid())
115             );
116         }
117     },
118 
119     _sceneOrder:function () {
120         this._isInSceneOnTop = this._back;
121     }
122 });
123 
124 /**
125  * Creates a base transition with duration and incoming scene.<br/>
126  * If back is true then the effect is reversed to appear as if the incoming<br/>
127  * scene is being turned from left over the outgoing scene.
128  * @deprecated since v3.0,please use new cc.TransitionPageTurn(t, scene, backwards) instead.
129  * @param {Number} t time in seconds
130  * @param {cc.Scene} scene
131  * @param {Boolean} backwards
132  * @return {cc.TransitionPageTurn}
133  * @example
134  * var myTransition = cc.TransitionPageTurn.create(1.5, nextScene, true)//true means backwards
135  */
136 cc.TransitionPageTurn.create = function (t, scene, backwards) {
137     return new cc.TransitionPageTurn(t, scene, backwards);
138 };
139