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