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