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._gridProxy = new cc.NodeGrid(); 53 this.initWithDuration(t, scene, backwards); 54 }, 55 56 /** 57 * @type Boolean 58 */ 59 _back:true, 60 _gridProxy: null, 61 _className:"TransitionPageTurn", 62 63 /** 64 * Creates a base transition with duration and incoming scene.<br/> 65 * If back is true then the effect is reversed to appear as if the incoming<br/> 66 * scene is being turned from left over the outgoing scene. 67 * @param {Number} t time in seconds 68 * @param {cc.Scene} scene 69 * @param {Boolean} backwards 70 * @return {Boolean} 71 */ 72 initWithDuration:function (t, scene, backwards) { 73 // XXX: needed before [super init] 74 this._back = backwards; 75 76 if (cc.TransitionScene.prototype.initWithDuration.call(this, t, scene)) { 77 // do something 78 } 79 return true; 80 }, 81 82 /** 83 * @param {cc.Size} vector 84 * @return {cc.ReverseTime|cc.TransitionScene} 85 */ 86 actionWithSize:function (vector) { 87 if (this._back) 88 return cc.reverseTime(cc.pageTurn3D(this._duration, vector)); // Get hold of the PageTurn3DAction 89 else 90 return cc.pageTurn3D(this._duration, vector); // Get hold of the PageTurn3DAction 91 }, 92 93 /** 94 * custom on enter 95 */ 96 onEnter:function () { 97 cc.TransitionScene.prototype.onEnter.call(this); 98 var winSize = cc.director.getWinSize(); 99 var x, y; 100 if (winSize.width > winSize.height) { 101 x = 16; 102 y = 12; 103 } else { 104 x = 12; 105 y = 16; 106 } 107 108 var action = this.actionWithSize(cc.size(x, y)), gridProxy = this._gridProxy; 109 110 if (!this._back) { 111 gridProxy.setTarget(this._outScene); 112 gridProxy.onEnter(); 113 gridProxy.runAction( cc.sequence(action,cc.callFunc(this.finish, this),cc.stopGrid())); 114 } else { 115 gridProxy.setTarget(this._inScene); 116 gridProxy.onEnter(); 117 // to prevent initial flicker 118 this._inScene.visible = false; 119 gridProxy.runAction( 120 cc.sequence(action, cc.callFunc(this.finish, this), cc.stopGrid()) 121 ); 122 this._inScene.runAction(cc.show()); 123 } 124 }, 125 126 visit: function(){ 127 //cc.TransitionScene.prototype.visit.call(this); 128 if(this._back) 129 this._outScene.visit(); 130 else 131 this._inScene.visit(); 132 this._gridProxy.visit(); 133 }, 134 135 _sceneOrder:function () { 136 this._isInSceneOnTop = this._back; 137 } 138 }); 139 140 /** 141 * Creates a base transition with duration and incoming scene.<br/> 142 * If back is true then the effect is reversed to appear as if the incoming<br/> 143 * scene is being turned from left over the outgoing scene. 144 * @deprecated since v3.0,please use new cc.TransitionPageTurn(t, scene, backwards) instead. 145 * @param {Number} t time in seconds 146 * @param {cc.Scene} scene 147 * @param {Boolean} backwards 148 * @return {cc.TransitionPageTurn} 149 */ 150 cc.TransitionPageTurn.create = function (t, scene, backwards) { 151 return new cc.TransitionPageTurn(t, scene, backwards); 152 }; 153