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 * tag for scene redial 29 * @constant 30 * @type Number 31 */ 32 cc.SCENE_RADIAL = 0xc001; 33 34 /** 35 * cc.TransitionProgress transition. 36 * @class 37 * @extends cc.TransitionScene 38 */ 39 cc.TransitionProgress = cc.TransitionScene.extend(/** @lends cc.TransitionProgress# */{ 40 _to:0, 41 _from:0, 42 _sceneToBeModified:null, 43 44 /** 45 * @override 46 */ 47 onEnter:function () { 48 cc.TransitionScene.prototype.onEnter.call(this); 49 this._setupTransition(); 50 51 // create a transparent color layer 52 // in which we are going to add our rendertextures 53 var winSize = cc.Director.getInstance().getWinSize(); 54 55 // create the second render texture for outScene 56 var texture = cc.RenderTexture.create(winSize.width, winSize.height); 57 texture.getSprite().setAnchorPoint(cc.p(0.5, 0.5)); 58 texture.setPosition(winSize.width / 2, winSize.height / 2); 59 texture.setAnchorPoint(cc.p(0.5, 0.5)); 60 61 // render outScene to its texturebuffer 62 texture.clear(0, 0, 0, 1); 63 texture.begin(); 64 this._sceneToBeModified.visit(); 65 texture.end(); 66 67 // Since we've passed the outScene to the texture we don't need it. 68 if (this._sceneToBeModified == this._outScene) 69 this.hideOutShowIn(); 70 71 // We need the texture in RenderTexture. 72 var pNode = this._progressTimerNodeWithRenderTexture(texture); 73 74 // create the blend action 75 var layerAction = cc.Sequence.create( 76 cc.ProgressFromTo.create(this._duration, this._from, this._to), 77 cc.CallFunc.create(this.finish, this)); 78 // run the blend action 79 pNode.runAction(layerAction); 80 81 // add the layer (which contains our two rendertextures) to the scene 82 this.addChild(pNode, 2, cc.SCENE_RADIAL); 83 }, 84 85 /** 86 * @override 87 */ 88 onExit:function () { 89 // remove our layer and release all containing objects 90 this.removeChildByTag(cc.SCENE_RADIAL, true); 91 cc.TransitionScene.prototype.onExit.call(this); 92 }, 93 94 _setupTransition:function () { 95 this._sceneToBeModified = this._outScene; 96 this._from = 100; 97 this._to = 0; 98 }, 99 100 _progressTimerNodeWithRenderTexture:function (texture) { 101 cc.Assert(false, "override me - abstract class"); 102 return null; 103 }, 104 105 _sceneOrder:function () { 106 this._isInSceneOnTop = false; 107 } 108 }); 109 110 /** 111 * create a cc.TransitionProgress object 112 * @function 113 * @param {Number} t time 114 * @param {cc.Scene} scene 115 * @return {cc.TransitionProgress} 116 */ 117 cc.TransitionProgress.create = function (t, scene) { 118 var tempScene = new cc.TransitionProgress(); 119 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 120 return tempScene; 121 } 122 return null; 123 }; 124 125 /** 126 * cc.TransitionRadialCCW transition.<br/> 127 * A counter colock-wise radial transition to the next scene 128 * @class 129 * @extends cc.TransitionProgress 130 */ 131 cc.TransitionProgressRadialCCW = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressRadialCCW# */{ 132 _progressTimerNodeWithRenderTexture:function (texture) { 133 var size = cc.Director.getInstance().getWinSize(); 134 135 var pNode = cc.ProgressTimer.create(texture.getSprite()); 136 137 // but it is flipped upside down so we flip the sprite 138 if (cc.renderContextType === cc.WEBGL) 139 pNode.getSprite().setFlippedY(true); 140 pNode.setType(cc.PROGRESS_TIMER_TYPE_RADIAL); 141 142 // Return the radial type that we want to use 143 pNode.setReverseDirection(false); 144 pNode.setPercentage(100); 145 pNode.setPosition(size.width / 2, size.height / 2); 146 pNode.setAnchorPoint(cc.p(0.5, 0.5)); 147 148 return pNode; 149 } 150 }); 151 152 /** 153 * create a cc.TransitionProgressRadialCCW object 154 * @function 155 * @param {Number} t time 156 * @param {cc.Scene} scene 157 * @return {cc.TransitionProgressRadialCCW} 158 */ 159 cc.TransitionProgressRadialCCW.create = function (t, scene) { 160 var tempScene = new cc.TransitionProgressRadialCCW(); 161 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 162 return tempScene; 163 } 164 return null; 165 }; 166 167 /** 168 * cc.TransitionRadialCW transition.<br/> 169 * A counter colock-wise radial transition to the next scene 170 * @class 171 * @extends cc.TransitionProgress 172 */ 173 cc.TransitionProgressRadialCW = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressRadialCW# */{ 174 _progressTimerNodeWithRenderTexture:function (texture) { 175 var size = cc.Director.getInstance().getWinSize(); 176 177 var pNode = cc.ProgressTimer.create(texture.getSprite()); 178 179 // but it is flipped upside down so we flip the sprite 180 if (cc.renderContextType === cc.WEBGL) 181 pNode.getSprite().setFlippedY(true); 182 pNode.setType(cc.PROGRESS_TIMER_TYPE_RADIAL); 183 184 // Return the radial type that we want to use 185 pNode.setReverseDirection(true); 186 pNode.setPercentage(100); 187 pNode.setPosition(size.width / 2, size.height / 2); 188 pNode.setAnchorPoint(cc.p(0.5, 0.5)); 189 190 return pNode; 191 } 192 }); 193 194 /** 195 * create a cc.TransitionProgressRadialCW object 196 * @function 197 * @param {Number} t time 198 * @param {cc.Scene} scene 199 * @return {cc.TransitionProgressRadialCW} 200 */ 201 cc.TransitionProgressRadialCW.create = function (t, scene) { 202 var tempScene = new cc.TransitionProgressRadialCW(); 203 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 204 return tempScene; 205 } 206 return null; 207 }; 208 209 /** 210 * cc.TransitionProgressHorizontal transition.<br/> 211 * A colock-wise radial transition to the next scene 212 * @class 213 * @extends cc.TransitionProgress 214 */ 215 cc.TransitionProgressHorizontal = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressHorizontal# */{ 216 _progressTimerNodeWithRenderTexture:function (texture) { 217 var size = cc.Director.getInstance().getWinSize(); 218 219 var pNode = cc.ProgressTimer.create(texture.getSprite()); 220 221 // but it is flipped upside down so we flip the sprite 222 if (cc.renderContextType === cc.WEBGL) 223 pNode.getSprite().setFlippedY(true); 224 pNode.setType(cc.PROGRESS_TIMER_TYPE_BAR); 225 226 pNode.setMidpoint(cc.p(1, 0)); 227 pNode.setBarChangeRate(cc.p(1, 0)); 228 229 pNode.setPercentage(100); 230 pNode.setPosition(size.width / 2, size.height / 2); 231 pNode.setAnchorPoint(cc.p(0.5, 0.5)); 232 233 return pNode; 234 } 235 }); 236 237 /** 238 * create a cc.TransitionProgressHorizontal object 239 * @function 240 * @param {Number} t time 241 * @param {cc.Scene} scene 242 * @return {cc.TransitionProgressHorizontal} 243 */ 244 cc.TransitionProgressHorizontal.create = function (t, scene) { 245 var tempScene = new cc.TransitionProgressHorizontal(); 246 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 247 return tempScene; 248 } 249 return null; 250 }; 251 252 /** 253 * cc.TransitionProgressVertical transition. 254 * @class 255 * @extends cc.TransitionProgress 256 */ 257 cc.TransitionProgressVertical = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressVertical# */{ 258 _progressTimerNodeWithRenderTexture:function (texture) { 259 var size = cc.Director.getInstance().getWinSize(); 260 261 var pNode = cc.ProgressTimer.create(texture.getSprite()); 262 263 // but it is flipped upside down so we flip the sprite 264 if (cc.renderContextType === cc.WEBGL) 265 pNode.getSprite().setFlippedY(true); 266 pNode.setType(cc.PROGRESS_TIMER_TYPE_BAR); 267 268 pNode.setMidpoint(cc.p(0, 0)); 269 pNode.setBarChangeRate(cc.p(0, 1)); 270 271 pNode.setPercentage(100); 272 pNode.setPosition(size.width / 2, size.height / 2); 273 pNode.setAnchorPoint(cc.p(0.5, 0.5)); 274 275 return pNode; 276 } 277 }); 278 279 /** 280 * create a cc.TransitionProgressVertical object 281 * @function 282 * @param {Number} t time 283 * @param {cc.Scene} scene 284 * @return {cc.TransitionProgressVertical} 285 */ 286 cc.TransitionProgressVertical.create = function (t, scene) { 287 var tempScene = new cc.TransitionProgressVertical(); 288 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 289 return tempScene; 290 } 291 return null; 292 }; 293 294 /** 295 * cc.TransitionProgressInOut transition. 296 * @class 297 * @extends cc.TransitionProgress 298 */ 299 cc.TransitionProgressInOut = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressInOut# */{ 300 _progressTimerNodeWithRenderTexture:function (texture) { 301 var size = cc.Director.getInstance().getWinSize(); 302 var pNode = cc.ProgressTimer.create(texture.getSprite()); 303 304 // but it is flipped upside down so we flip the sprite 305 if (cc.renderContextType === cc.WEBGL) 306 pNode.getSprite().setFlippedY(true); 307 pNode.setType(cc.PROGRESS_TIMER_TYPE_BAR); 308 309 pNode.setMidpoint(cc.p(0.5, 0.5)); 310 pNode.setBarChangeRate(cc.p(1, 1)); 311 312 pNode.setPercentage(0); 313 pNode.setPosition(size.width / 2, size.height / 2); 314 pNode.setAnchorPoint(cc.p(0.5, 0.5)); 315 316 return pNode; 317 }, 318 _sceneOrder:function () { 319 this._isInSceneOnTop = false; 320 }, 321 _setupTransition:function () { 322 this._sceneToBeModified = this._inScene; 323 this._from = 0; 324 this._to = 100; 325 } 326 }); 327 328 /** 329 * create a cc.TransitionProgressInOut object 330 * @function 331 * @param {Number} t time 332 * @param {cc.Scene} scene 333 * @return {cc.TransitionProgressInOut} 334 */ 335 cc.TransitionProgressInOut.create = function (t, scene) { 336 var tempScene = new cc.TransitionProgressInOut(); 337 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 338 return tempScene; 339 } 340 return null; 341 }; 342 343 /** 344 * cc.TransitionProgressOutIn transition. 345 * @class 346 * @extends cc.TransitionProgress 347 */ 348 cc.TransitionProgressOutIn = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressOutIn# */{ 349 _progressTimerNodeWithRenderTexture:function (texture) { 350 var size = cc.Director.getInstance().getWinSize(); 351 var pNode = cc.ProgressTimer.create(texture.getSprite()); 352 353 // but it is flipped upside down so we flip the sprite 354 if (cc.renderContextType === cc.WEBGL) 355 pNode.getSprite().setFlippedY(true); 356 pNode.setType(cc.PROGRESS_TIMER_TYPE_BAR); 357 358 pNode.setMidpoint(cc.p(0.5, 0.5)); 359 pNode.setBarChangeRate(cc.p(1, 1)); 360 361 pNode.setPercentage(100); 362 pNode.setPosition(size.width / 2, size.height / 2); 363 pNode.setAnchorPoint(cc.p(0.5, 0.5)); 364 365 return pNode; 366 } 367 }); 368 369 /** 370 * create a cc.TransitionProgressOutIn object 371 * @function 372 * @param {Number} t time 373 * @param {cc.Scene} scene 374 * @return {cc.TransitionProgressOutIn} 375 */ 376 cc.TransitionProgressOutIn.create = function (t, scene) { 377 var tempScene = new cc.TransitionProgressOutIn(); 378 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 379 return tempScene; 380 } 381 return null; 382 }; 383