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 * 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 _className:"TransitionProgress", 44 45 /** 46 * @constructor 47 * @param {Number} t time 48 * @param {cc.Scene} scene 49 */ 50 ctor:function (t, scene) { 51 cc.TransitionScene.prototype.ctor.call(this); 52 scene && this.initWithDuration(t, scene); 53 }, 54 55 _setAttrs: function(node, x, y) { 56 node.attr({ 57 x: x, 58 y: y, 59 anchorX: 0.5, 60 anchorY: 0.5 61 }); 62 }, 63 64 /** 65 * @override 66 */ 67 onEnter:function () { 68 cc.TransitionScene.prototype.onEnter.call(this); 69 this._setupTransition(); 70 71 // create a transparent color layer 72 // in which we are going to add our rendertextures 73 var winSize = cc.director.getWinSize(); 74 75 // create the second render texture for outScene 76 var texture = cc.RenderTexture.create(winSize.width, winSize.height); 77 texture.sprite.anchorX = 0.5; 78 texture.sprite.anchorY = 0.5; 79 this._setAttrs(texture, winSize.width / 2, winSize.height / 2); 80 81 // render outScene to its texturebuffer 82 texture.clear(0, 0, 0, 1); 83 texture.begin(); 84 this._sceneToBeModified.visit(); 85 texture.end(); 86 87 // Since we've passed the outScene to the texture we don't need it. 88 if (this._sceneToBeModified == this._outScene) 89 this.hideOutShowIn(); 90 91 // We need the texture in RenderTexture. 92 var pNode = this._progressTimerNodeWithRenderTexture(texture); 93 94 // create the blend action 95 var layerAction = cc.sequence( 96 cc.progressFromTo(this._duration, this._from, this._to), 97 cc.callFunc(this.finish, this)); 98 // run the blend action 99 pNode.runAction(layerAction); 100 101 // add the layer (which contains our two rendertextures) to the scene 102 this.addChild(pNode, 2, cc.SCENE_RADIAL); 103 }, 104 105 /** 106 * @override 107 */ 108 onExit:function () { 109 // remove our layer and release all containing objects 110 this.removeChildByTag(cc.SCENE_RADIAL, true); 111 cc.TransitionScene.prototype.onExit.call(this); 112 }, 113 114 _setupTransition:function () { 115 this._sceneToBeModified = this._outScene; 116 this._from = 100; 117 this._to = 0; 118 }, 119 120 _progressTimerNodeWithRenderTexture:function (texture) { 121 cc.log("cc.TransitionProgress._progressTimerNodeWithRenderTexture(): should be overridden in subclass"); 122 return null; 123 }, 124 125 _sceneOrder:function () { 126 this._isInSceneOnTop = false; 127 } 128 }); 129 130 /** 131 * create a cc.TransitionProgress object 132 * @deprecated 133 * @function 134 * @param {Number} t time 135 * @param {cc.Scene} scene 136 * @return {cc.TransitionProgress} 137 */ 138 cc.TransitionProgress.create = function (t, scene) { 139 return new cc.TransitionProgress(t, scene); 140 }; 141 142 /** 143 * cc.TransitionRadialCCW transition.<br/> 144 * A counter clock-wise radial transition to the next scene 145 * @class 146 * @extends cc.TransitionProgress 147 */ 148 cc.TransitionProgressRadialCCW = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressRadialCCW# */{ 149 150 /** 151 * @constructor 152 * @param {Number} t time 153 * @param {cc.Scene} scene 154 */ 155 ctor:function (t, scene) { 156 cc.TransitionProgress.prototype.ctor.call(this); 157 scene && this.initWithDuration(t, scene); 158 }, 159 160 _progressTimerNodeWithRenderTexture:function (texture) { 161 var size = cc.director.getWinSize(); 162 163 var pNode = cc.ProgressTimer.create(texture.sprite); 164 165 // but it is flipped upside down so we flip the sprite 166 if (cc._renderType === cc._RENDER_TYPE_WEBGL) 167 pNode.sprite.flippedY = true; 168 pNode.type = cc.ProgressTimer.TYPE_RADIAL; 169 170 // Return the radial type that we want to use 171 pNode.reverseDir = false; 172 pNode.percentage = 100; 173 this._setAttrs(pNode, size.width / 2, size.height / 2); 174 175 return pNode; 176 } 177 }); 178 179 /** 180 * create a cc.TransitionProgressRadialCCW object 181 * @function 182 * @deprecated 183 * @param {Number} t time 184 * @param {cc.Scene} scene 185 * @return {cc.TransitionProgressRadialCCW} 186 */ 187 cc.TransitionProgressRadialCCW.create = function (t, scene) { 188 return new cc.TransitionProgressRadialCCW(t, scene); 189 }; 190 191 /** 192 * cc.TransitionRadialCW transition.<br/> 193 * A counter colock-wise radial transition to the next scene 194 * @class 195 * @extends cc.TransitionProgress 196 */ 197 cc.TransitionProgressRadialCW = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressRadialCW# */{ 198 /** 199 * @constructor 200 * @param {Number} t time 201 * @param {cc.Scene} scene 202 */ 203 ctor:function (t, scene) { 204 cc.TransitionProgress.prototype.ctor.call(this); 205 scene && this.initWithDuration(t, scene); 206 }, 207 208 _progressTimerNodeWithRenderTexture:function (texture) { 209 var size = cc.director.getWinSize(); 210 211 var pNode = cc.ProgressTimer.create(texture.sprite); 212 213 // but it is flipped upside down so we flip the sprite 214 if (cc._renderType === cc._RENDER_TYPE_WEBGL) 215 pNode.sprite.flippedY = true; 216 pNode.type = cc.ProgressTimer.TYPE_RADIAL; 217 218 // Return the radial type that we want to use 219 pNode.reverseDir = true; 220 pNode.percentage = 100; 221 this._setAttrs(pNode, size.width / 2, size.height / 2); 222 223 return pNode; 224 } 225 }); 226 227 /** 228 * create a cc.TransitionProgressRadialCW object 229 * @function 230 * @deprecated 231 * @param {Number} t time 232 * @param {cc.Scene} scene 233 * @return {cc.TransitionProgressRadialCW} 234 */ 235 cc.TransitionProgressRadialCW.create = function (t, scene) { 236 var tempScene = new cc.TransitionProgressRadialCW(); 237 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 238 return tempScene; 239 } 240 return new cc.TransitionProgressRadialCW(t, scene); 241 }; 242 243 /** 244 * cc.TransitionProgressHorizontal transition.<br/> 245 * A colock-wise radial transition to the next scene 246 * @class 247 * @extends cc.TransitionProgress 248 */ 249 cc.TransitionProgressHorizontal = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressHorizontal# */{ 250 /** 251 * @constructor 252 * @param {Number} t time 253 * @param {cc.Scene} scene 254 */ 255 ctor:function (t, scene) { 256 cc.TransitionProgress.prototype.ctor.call(this); 257 scene && this.initWithDuration(t, scene); 258 }, 259 260 _progressTimerNodeWithRenderTexture:function (texture) { 261 var size = cc.director.getWinSize(); 262 263 var pNode = cc.ProgressTimer.create(texture.sprite); 264 265 // but it is flipped upside down so we flip the sprite 266 if (cc._renderType === cc._RENDER_TYPE_WEBGL) 267 pNode.sprite.flippedY = true; 268 pNode.type = cc.ProgressTimer.TYPE_BAR; 269 270 pNode.midPoint = cc.p(1, 0); 271 pNode.barChangeRate = cc.p(1, 0); 272 273 pNode.percentage = 100; 274 this._setAttrs(pNode, size.width / 2, size.height / 2); 275 276 return pNode; 277 } 278 }); 279 280 /** 281 * create a cc.TransitionProgressHorizontal object 282 * @function 283 * @deprecated 284 * @param {Number} t time 285 * @param {cc.Scene} scene 286 * @return {cc.TransitionProgressHorizontal} 287 */ 288 cc.TransitionProgressHorizontal.create = function (t, scene) { 289 return new cc.TransitionProgressHorizontal(t, scene); 290 }; 291 292 /** 293 * cc.TransitionProgressVertical transition. 294 * @class 295 * @extends cc.TransitionProgress 296 */ 297 cc.TransitionProgressVertical = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressVertical# */{ 298 299 /** 300 * @constructor 301 * @param {Number} t time 302 * @param {cc.Scene} scene 303 */ 304 ctor:function (t, scene) { 305 cc.TransitionProgress.prototype.ctor.call(this); 306 scene && this.initWithDuration(t, scene); 307 }, 308 309 _progressTimerNodeWithRenderTexture:function (texture) { 310 var size = cc.director.getWinSize(); 311 312 var pNode = cc.ProgressTimer.create(texture.sprite); 313 314 // but it is flipped upside down so we flip the sprite 315 if (cc._renderType === cc._RENDER_TYPE_WEBGL) 316 pNode.sprite.flippedY = true; 317 pNode.type = cc.ProgressTimer.TYPE_BAR; 318 319 pNode.midPoint = cc.p(0, 0); 320 pNode.barChangeRate = cc.p(0, 1); 321 322 pNode.percentage = 100; 323 this._setAttrs(pNode, size.width / 2, size.height / 2); 324 325 return pNode; 326 } 327 }); 328 329 /** 330 * create a cc.TransitionProgressVertical object 331 * @function 332 * @deprecated 333 * @param {Number} t time 334 * @param {cc.Scene} scene 335 * @return {cc.TransitionProgressVertical} 336 */ 337 cc.TransitionProgressVertical.create = function (t, scene) { 338 return new cc.TransitionProgressVertical(t, scene); 339 }; 340 341 /** 342 * cc.TransitionProgressInOut transition. 343 * @class 344 * @extends cc.TransitionProgress 345 */ 346 cc.TransitionProgressInOut = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressInOut# */{ 347 348 /** 349 * @constructor 350 * @param {Number} t time 351 * @param {cc.Scene} scene 352 */ 353 ctor:function (t, scene) { 354 cc.TransitionProgress.prototype.ctor.call(this); 355 scene && this.initWithDuration(t, scene); 356 }, 357 358 _progressTimerNodeWithRenderTexture:function (texture) { 359 var size = cc.director.getWinSize(); 360 var pNode = cc.ProgressTimer.create(texture.sprite); 361 362 // but it is flipped upside down so we flip the sprite 363 if (cc._renderType === cc._RENDER_TYPE_WEBGL) 364 pNode.sprite.flippedY = true; 365 pNode.type = cc.ProgressTimer.TYPE_BAR; 366 367 pNode.midPoint = cc.p(0.5, 0.5); 368 pNode.barChangeRate = cc.p(1, 1); 369 370 pNode.percentage = 0; 371 this._setAttrs(pNode, size.width / 2, size.height / 2); 372 373 return pNode; 374 }, 375 _sceneOrder:function () { 376 this._isInSceneOnTop = false; 377 }, 378 _setupTransition:function () { 379 this._sceneToBeModified = this._inScene; 380 this._from = 0; 381 this._to = 100; 382 } 383 }); 384 385 /** 386 * create a cc.TransitionProgressInOut object 387 * @function 388 * @deprecated 389 * @param {Number} t time 390 * @param {cc.Scene} scene 391 * @return {cc.TransitionProgressInOut} 392 */ 393 cc.TransitionProgressInOut.create = function (t, scene) { 394 return new cc.TransitionProgressInOut(t, scene); 395 }; 396 397 /** 398 * cc.TransitionProgressOutIn transition. 399 * @class 400 * @extends cc.TransitionProgress 401 */ 402 cc.TransitionProgressOutIn = cc.TransitionProgress.extend(/** @lends cc.TransitionProgressOutIn# */{ 403 404 /** 405 * @constructor 406 * @param {Number} t time 407 * @param {cc.Scene} scene 408 */ 409 ctor:function (t, scene) { 410 cc.TransitionProgress.prototype.ctor.call(this); 411 scene && this.initWithDuration(t, scene); 412 }, 413 414 _progressTimerNodeWithRenderTexture:function (texture) { 415 var size = cc.director.getWinSize(); 416 var pNode = cc.ProgressTimer.create(texture.sprite); 417 418 // but it is flipped upside down so we flip the sprite 419 if (cc._renderType === cc._RENDER_TYPE_WEBGL) 420 pNode.sprite.flippedY = true; 421 pNode.type = cc.ProgressTimer.TYPE_BAR; 422 423 pNode.midPoint = cc.p(0.5, 0.5); 424 pNode.barChangeRate = cc.p(1, 1); 425 426 pNode.percentage = 100; 427 this._setAttrs(pNode, size.width / 2, size.height / 2); 428 429 return pNode; 430 } 431 }); 432 433 /** 434 * create a cc.TransitionProgressOutIn object 435 * @function 436 * @deprecated 437 * @param {Number} t time 438 * @param {cc.Scene} scene 439 * @return {cc.TransitionProgressOutIn} 440 */ 441 cc.TransitionProgressOutIn.create = function (t, scene) { 442 return new cc.TransitionProgressOutIn(t, scene); 443 }; 444