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 */ 38 cc.TransitionPageTurn = cc.TransitionScene.extend(/** @lends cc.TransitionPageTurn# */{ 39 40 /** 41 * @constructor 42 * @param {Number} t time in seconds 43 * @param {cc.Scene} scene 44 * @param {Boolean} backwards 45 */ 46 ctor:function (t, scene, backwards) { 47 cc.TransitionScene.prototype.ctor.call(this); 48 this.initWithDuration(t, scene, backwards); 49 }, 50 51 /** 52 * @type Boolean 53 */ 54 _back:true, 55 _className:"TransitionPageTurn", 56 57 /** 58 * Creates a base transition with duration and incoming scene.<br/> 59 * If back is true then the effect is reversed to appear as if the incoming<br/> 60 * scene is being turned from left over the outgoing scene. 61 * @param {Number} t time in seconds 62 * @param {cc.Scene} scene 63 * @param {Boolean} backwards 64 * @return {Boolean} 65 */ 66 initWithDuration:function (t, scene, backwards) { 67 // XXX: needed before [super init] 68 this._back = backwards; 69 70 if (cc.TransitionScene.prototype.initWithDuration.call(this, t, scene)) { 71 // do something 72 } 73 return true; 74 }, 75 76 /** 77 * @param {cc.Size} vector 78 * @return {cc.ReverseTime|cc.TransitionScene} 79 */ 80 actionWithSize:function (vector) { 81 if (this._back) 82 return cc.ReverseTime.create(cc.PageTurn3D.create(this._duration, vector)); // Get hold of the PageTurn3DAction 83 else 84 return cc.PageTurn3D.create(this._duration, vector); // Get hold of the PageTurn3DAction 85 }, 86 87 /** 88 * custom on enter 89 */ 90 onEnter:function () { 91 cc.TransitionScene.prototype.onEnter.call(this); 92 var winSize = cc.director.getWinSize(); 93 var x, y; 94 if (winSize.width > winSize.height) { 95 x = 16; 96 y = 12; 97 } else { 98 x = 12; 99 y = 16; 100 } 101 102 var action = this.actionWithSize(cc.size(x, y)); 103 104 if (!this._back) { 105 this._outScene.runAction( cc.Sequence.create(action,cc.CallFunc.create(this.finish, this),cc.StopGrid.create())); 106 } else { 107 // to prevent initial flicker 108 this._inScene.visible = false; 109 this._inScene.runAction( 110 cc.Sequence.create(cc.Show.create(),action, cc.CallFunc.create(this.finish, this), cc.StopGrid.create()) 111 ); 112 } 113 }, 114 115 _sceneOrder:function () { 116 this._isInSceneOnTop = this._back; 117 } 118 }); 119 120 /** 121 * Creates a base transition with duration and incoming scene.<br/> 122 * If back is true then the effect is reversed to appear as if the incoming<br/> 123 * scene is being turned from left over the outgoing scene. 124 * @deprecated 125 * @param {Number} t time in seconds 126 * @param {cc.Scene} scene 127 * @param {Boolean} backwards 128 * @return {cc.TransitionPageTurn} 129 * @example 130 * // Example 131 * var myTransition = cc.TransitionPageTurn.create(1.5, nextScene, true)//true means backwards 132 */ 133 cc.TransitionPageTurn.create = function (t, scene, backwards) { 134 return new cc.TransitionPageTurn(t, scene, backwards); 135 }; 136