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