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