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 * A tag constant for identifying fade scenes 28 * @constant 29 * @type Number 30 */ 31 cc.SCENE_FADE = 4208917214; 32 33 /** 34 * cc.TransitionEaseScene can ease the actions of the scene protocol. 35 * @class 36 * @extends cc.Class 37 */ 38 cc.TransitionEaseScene = cc.Class.extend(/** @lends cc.TransitionEaseScene# */{ 39 /** 40 * returns the Ease action that will be performed on a linear action. 41 */ 42 easeActionWithAction:function () { 43 } 44 }); 45 46 /** 47 * horizontal orientation Type where the Left is nearer 48 * @constant 49 * @type Number 50 */ 51 cc.TRANSITION_ORIENTATION_LEFT_OVER = 0; 52 /** 53 * horizontal orientation type where the Right is nearer 54 * @constant 55 * @type Number 56 */ 57 cc.TRANSITION_ORIENTATION_RIGHT_OVER = 1; 58 /** 59 * vertical orientation type where the Up is nearer 60 * @constant 61 * @type Number 62 */ 63 cc.TRANSITION_ORIENTATION_UP_OVER = 0; 64 /** 65 * vertical orientation type where the Bottom is nearer 66 * @constant 67 * @type Number 68 */ 69 cc.TRANSITION_ORIENTATION_DOWN_OVER = 1; 70 71 /** 72 * @class 73 * @extends cc.Scene 74 */ 75 cc.TransitionScene = cc.Scene.extend(/** @lends cc.TransitionScene# */{ 76 _inScene:null, 77 _outScene:null, 78 _duration:null, 79 _isInSceneOnTop:false, 80 _isSendCleanupToScene:false, 81 82 //private 83 _setNewScene:function (dt) { 84 this.unschedule(this._setNewScene); 85 // Before replacing, save the "send cleanup to scene" 86 var director = cc.Director.getInstance(); 87 this._isSendCleanupToScene = director.isSendCleanupToScene(); 88 director.replaceScene(this._inScene); 89 90 // enable events while transitions 91 if(cc.TouchDispatcher) 92 director.getTouchDispatcher().setDispatchEvents(true); 93 // issue #267 94 this._outScene.setVisible(true); 95 }, 96 97 //protected 98 _sceneOrder:function () { 99 this._isInSceneOnTop = true; 100 }, 101 102 /** 103 * stuff gets drawn here 104 */ 105 draw:function () { 106 if (this._isInSceneOnTop) { 107 this._outScene.visit(); 108 this._inScene.visit(); 109 } else { 110 this._inScene.visit(); 111 this._outScene.visit(); 112 } 113 }, 114 115 /** 116 * custom onEnter 117 */ 118 onEnter:function () { 119 cc.Node.prototype.onEnter.call(this); 120 121 // disable events while transitions 122 if(cc.TouchDispatcher) 123 cc.Director.getInstance().getTouchDispatcher().setDispatchEvents(false); 124 125 // outScene should not receive the onEnter callback 126 // only the onExitTransitionDidStart 127 this._outScene.onExitTransitionDidStart(); 128 129 this._inScene.onEnter(); 130 }, 131 132 /** 133 * custom onExit 134 */ 135 onExit:function () { 136 cc.Node.prototype.onExit.call(this); 137 138 // enable events while transitions 139 if(cc.TouchDispatcher) 140 cc.Director.getInstance().getTouchDispatcher().setDispatchEvents(true); 141 142 this._outScene.onExit(); 143 144 // _inScene should not receive the onEnter callback 145 // only the onEnterTransitionDidFinish 146 this._inScene.onEnterTransitionDidFinish(); 147 }, 148 149 /** 150 * custom cleanup 151 */ 152 cleanup:function () { 153 cc.Node.prototype.cleanup.call(this); 154 155 if (this._isSendCleanupToScene) 156 this._outScene.cleanup(); 157 }, 158 159 /** 160 * initializes a transition with duration and incoming scene 161 * @param {Number} t time in seconds 162 * @param {cc.Scene} scene a scene to transit to 163 * @return {Boolean} return false if error 164 */ 165 initWithDuration:function (t, scene) { 166 if(!scene) 167 throw "cc.TransitionScene.initWithDuration(): Argument scene must be non-nil"; 168 169 if (this.init()) { 170 this._duration = t; 171 this.setAnchorPoint(0, 0); 172 this.setPosition(0, 0); 173 // retain 174 this._inScene = scene; 175 this._outScene = cc.Director.getInstance().getRunningScene(); 176 if (!this._outScene) { 177 this._outScene = cc.Scene.create(); 178 this._outScene.init(); 179 } 180 181 if(this._inScene == this._outScene) 182 throw "cc.TransitionScene.initWithDuration(): Incoming scene must be different from the outgoing scene"; 183 184 this._sceneOrder(); 185 return true; 186 } else { 187 return false; 188 } 189 }, 190 191 /** 192 * called after the transition finishes 193 */ 194 finish:function () { 195 // clean up 196 this._inScene.setVisible(true); 197 this._inScene.setPosition(0, 0); 198 this._inScene.setScale(1.0); 199 this._inScene.setRotation(0.0); 200 if(cc.renderContextType === cc.WEBGL) 201 this._inScene.getCamera().restore(); 202 203 this._outScene.setVisible(false); 204 this._outScene.setPosition(0, 0); 205 this._outScene.setScale(1.0); 206 this._outScene.setRotation(0.0); 207 if(cc.renderContextType === cc.WEBGL) 208 this._outScene.getCamera().restore(); 209 210 //[self schedule:@selector(setNewScene:) interval:0]; 211 this.schedule(this._setNewScene, 0); 212 }, 213 214 /** 215 * set hide the out scene and show in scene 216 */ 217 hideOutShowIn:function () { 218 this._inScene.setVisible(true); 219 this._outScene.setVisible(false); 220 } 221 }); 222 /** 223 * creates a base transition with duration and incoming scene 224 * @param {Number} t time in seconds 225 * @param {cc.Scene} scene the scene to transit with 226 * @return {cc.TransitionScene|Null} 227 */ 228 cc.TransitionScene.create = function (t, scene) { 229 var tempScene = new cc.TransitionScene(); 230 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 231 return tempScene; 232 } 233 return null; 234 }; 235 236 /** 237 * A cc.Transition that supports orientation like.<br/> 238 * Possible orientation: LeftOver, RightOver, UpOver, DownOver<br/> 239 * useful for when you want to make a transition happen between 2 orientations 240 * @class 241 * @extends cc.TransitionScene 242 */ 243 cc.TransitionSceneOriented = cc.TransitionScene.extend(/** @lends cc.TransitionSceneOriented# */{ 244 _orientation:0, 245 246 /** 247 * initialize the transition 248 * @param {Number} t time in seconds 249 * @param {cc.Scene} scene 250 * @param {cc.TRANSITION_ORIENTATION_LEFT_OVER|cc.TRANSITION_ORIENTATION_RIGHT_OVER|cc.TRANSITION_ORIENTATION_UP_OVER|cc.TRANSITION_ORIENTATION_DOWN_OVER} orientation 251 * @return {Boolean} 252 */ 253 initWithDuration:function (t, scene, orientation) { 254 if (cc.TransitionScene.prototype.initWithDuration.call(this, t, scene)) { 255 this._orientation = orientation; 256 } 257 return true; 258 } 259 }); 260 261 /** 262 * creates a base transition with duration and incoming scene 263 * @param {Number} t time in seconds 264 * @param {cc.Scene} scene 265 * @param {cc.TRANSITION_ORIENTATION_LEFT_OVER|cc.TRANSITION_ORIENTATION_RIGHT_OVER|cc.TRANSITION_ORIENTATION_UP_OVER|cc.TRANSITION_ORIENTATION_DOWN_OVER} orientation 266 * @return {cc.TransitionSceneOriented} 267 * @example 268 * // Example 269 * var goHorizontal = cc.TransitionSceneOriented.create(0.5, thisScene, cc.TRANSITION_ORIENTATION_LEFT_OVER) 270 */ 271 cc.TransitionSceneOriented.create = function (t, scene, orientation) { 272 var tempScene = new cc.TransitionSceneOriented(); 273 tempScene.initWithDuration(t, scene, orientation); 274 275 return tempScene; 276 }; 277 278 /** 279 * Rotate and zoom out the outgoing scene, and then rotate and zoom in the incoming 280 * @class 281 * @extends cc.TransitionScene 282 */ 283 cc.TransitionRotoZoom = cc.TransitionScene.extend(/** @lends cc.TransitionRotoZoom# */{ 284 /** 285 * Custom On Enter callback 286 * @override 287 */ 288 onEnter:function () { 289 cc.TransitionScene.prototype.onEnter.call(this); 290 291 this._inScene.setScale(0.001); 292 this._outScene.setScale(1.0); 293 294 this._inScene.setAnchorPoint(0.5, 0.5); 295 this._outScene.setAnchorPoint(0.5, 0.5); 296 297 var rotoZoom = cc.Sequence.create( 298 cc.Spawn.create(cc.ScaleBy.create(this._duration / 2, 0.001), 299 cc.RotateBy.create(this._duration / 2, 360 * 2)), 300 cc.DelayTime.create(this._duration / 2)); 301 302 this._outScene.runAction(rotoZoom); 303 this._inScene.runAction( 304 cc.Sequence.create(rotoZoom.reverse(), 305 cc.CallFunc.create(this.finish, this))); 306 } 307 }); 308 309 /** 310 * Creates a Transtion rotation and zoom 311 * @param {Number} t time in seconds 312 * @param {cc.Scene} scene the scene to work with 313 * @return {cc.TransitionRotoZoom} 314 * @example 315 * // Example 316 * var RotoZoomTrans = cc.TransitionRotoZoom.create(2, nextScene); 317 */ 318 cc.TransitionRotoZoom.create = function (t, scene) { 319 var tempScene = new cc.TransitionRotoZoom(); 320 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 321 return tempScene; 322 } 323 return null; 324 }; 325 326 /** 327 * Zoom out and jump the outgoing scene, and then jump and zoom in the incoming 328 * @class 329 * @extends cc.TransitionScene 330 */ 331 cc.TransitionJumpZoom = cc.TransitionScene.extend(/** @lends cc.TransitionJumpZoom# */{ 332 /** 333 * Custom on enter 334 */ 335 onEnter:function () { 336 cc.TransitionScene.prototype.onEnter.call(this); 337 var winSize = cc.Director.getInstance().getWinSize(); 338 339 this._inScene.setScale(0.5); 340 this._inScene.setPosition(winSize.width, 0); 341 this._inScene.setAnchorPoint(0.5, 0.5); 342 this._outScene.setAnchorPoint(0.5, 0.5); 343 344 var jump = cc.JumpBy.create(this._duration / 4, cc.p(-winSize.width, 0), winSize.width / 4, 2); 345 var scaleIn = cc.ScaleTo.create(this._duration / 4, 1.0); 346 var scaleOut = cc.ScaleTo.create(this._duration / 4, 0.5); 347 348 var jumpZoomOut = cc.Sequence.create(scaleOut, jump); 349 var jumpZoomIn = cc.Sequence.create(jump, scaleIn); 350 351 var delay = cc.DelayTime.create(this._duration / 2); 352 this._outScene.runAction(jumpZoomOut); 353 this._inScene.runAction(cc.Sequence.create(delay, jumpZoomIn, cc.CallFunc.create(this.finish, this))); 354 } 355 }); 356 357 /** 358 * creates a scene transition that zooms then jump across the screen, the same for the incoming scene 359 * @param {Number} t time in seconds 360 * @param {cc.Scene} scene 361 * @return {cc.TransitionJumpZoom} 362 */ 363 cc.TransitionJumpZoom.create = function (t, scene) { 364 var tempScene = new cc.TransitionJumpZoom(); 365 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 366 return tempScene; 367 } 368 return null; 369 }; 370 371 /** 372 * Move in from to the left the incoming scene. 373 * @class 374 * @extends cc.TransitionScene 375 */ 376 cc.TransitionMoveInL = cc.TransitionScene.extend(/** @lends cc.TransitionMoveInL# */{ 377 378 /** 379 * Custom on enter 380 */ 381 onEnter:function () { 382 cc.TransitionScene.prototype.onEnter.call(this); 383 this.initScenes(); 384 385 var action = this.action(); 386 this._inScene.runAction( 387 cc.Sequence.create(this.easeActionWithAction(action), cc.CallFunc.create(this.finish, this)) 388 ); 389 }, 390 391 /** 392 * initializes the scenes 393 */ 394 initScenes:function () { 395 this._inScene.setPosition(-cc.Director.getInstance().getWinSize().width, 0); 396 }, 397 398 /** 399 * returns the action that will be performed 400 */ 401 action:function () { 402 return cc.MoveTo.create(this._duration, cc.p(0, 0)); 403 }, 404 405 /** 406 * creates an ease action from action 407 * @param {cc.ActionInterval} action 408 * @return {cc.EaseOut} 409 */ 410 easeActionWithAction:function (action) { 411 return cc.EaseOut.create(action, 2.0); 412 } 413 }); 414 415 /** 416 * creates an action that Move in from to the left the incoming scene. 417 * @param {Number} t time in seconds 418 * @param {cc.Scene} scene 419 * @return {cc.TransitionMoveInL} 420 * @example 421 * // Example 422 * var MoveInLeft = cc.TransitionMoveInL.create(1, nextScene) 423 */ 424 cc.TransitionMoveInL.create = function (t, scene) { 425 var tempScene = new cc.TransitionMoveInL(); 426 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 427 return tempScene; 428 } 429 return null; 430 }; 431 432 /** 433 * Move in from to the right the incoming scene. 434 * @class 435 * @extends cc.TransitionMoveInL 436 */ 437 cc.TransitionMoveInR = cc.TransitionMoveInL.extend(/** @lends cc.TransitionMoveInR# */{ 438 /** 439 * Init 440 */ 441 initScenes:function () { 442 this._inScene.setPosition(cc.Director.getInstance().getWinSize().width, 0); 443 } 444 }); 445 446 /** 447 * create a scene transition that Move in from to the right the incoming scene. 448 * @param {Number} t time in seconds 449 * @param {cc.Scene} scene 450 * @return {cc.TransitionMoveInR} 451 * @example 452 * // Example 453 * var MoveInRight = cc.TransitionMoveInR.create(1, nextScene) 454 */ 455 cc.TransitionMoveInR.create = function (t, scene) { 456 var tempScene = new cc.TransitionMoveInR(); 457 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 458 return tempScene; 459 } 460 return null; 461 }; 462 463 /** 464 * Move in from to the top the incoming scene. 465 * @class 466 * @extends cc.TransitionMoveInL 467 */ 468 cc.TransitionMoveInT = cc.TransitionMoveInL.extend(/** @lends cc.TransitionMoveInT# */{ 469 470 /** 471 * init 472 */ 473 initScenes:function () { 474 this._inScene.setPosition(0, cc.Director.getInstance().getWinSize().height); 475 } 476 }); 477 478 /** 479 * Move in from to the top the incoming scene. 480 * @param {Number} t time in seconds 481 * @param {cc.Scene} scene 482 * @return {cc.TransitionMoveInT} 483 * @example 484 * // Example 485 * var MoveInTop = cc.TransitionMoveInT.create(1, nextScene) 486 */ 487 cc.TransitionMoveInT.create = function (t, scene) { 488 var tempScene = new cc.TransitionMoveInT(); 489 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 490 return tempScene; 491 } 492 return null; 493 }; 494 495 /** 496 * Move in from to the bottom the incoming scene. 497 * @class 498 * @extends cc.TransitionMoveInL 499 */ 500 cc.TransitionMoveInB = cc.TransitionMoveInL.extend(/** @lends cc.TransitionMoveInB# */{ 501 502 /** 503 * init 504 */ 505 initScenes:function () { 506 this._inScene.setPosition(0, -cc.Director.getInstance().getWinSize().height); 507 } 508 }); 509 510 /** 511 * create a scene transition that Move in from to the bottom the incoming scene. 512 * @param {Number} t time in seconds 513 * @param {cc.Scene} scene 514 * @return {cc.TransitionMoveInB} 515 * @example 516 * // Example 517 * var MoveinB = cc.TransitionMoveInB.create(1, nextScene) 518 */ 519 cc.TransitionMoveInB.create = function (t, scene) { 520 var tempScene = new cc.TransitionMoveInB(); 521 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 522 return tempScene; 523 } 524 return null; 525 }; 526 527 /** 528 * The adjust factor is needed to prevent issue #442<br/> 529 * One solution is to use DONT_RENDER_IN_SUBPIXELS images, but NO<br/> 530 * The other issue is that in some transitions (and I don't know why)<br/> 531 * the order should be reversed (In in top of Out or vice-versa). 532 * @constant 533 * @type Number 534 */ 535 cc.ADJUST_FACTOR = 0.5; 536 537 /** 538 * a transition that a new scene is slided from left 539 * @class 540 * @extends cc.TransitionScene 541 */ 542 cc.TransitionSlideInL = cc.TransitionScene.extend(/** @lends cc.TransitionSlideInL# */{ 543 _sceneOrder:function () { 544 this._isInSceneOnTop = false; 545 }, 546 547 /** 548 * custom on enter 549 */ 550 onEnter:function () { 551 cc.TransitionScene.prototype.onEnter.call(this); 552 this.initScenes(); 553 554 var inA = this.action(); 555 var outA = this.action(); 556 557 var inAction = this.easeActionWithAction(inA); 558 var outAction = cc.Sequence.create(this.easeActionWithAction(outA), cc.CallFunc.create(this.finish, this)); 559 this._inScene.runAction(inAction); 560 this._outScene.runAction(outAction); 561 }, 562 563 /** 564 * initializes the scenes 565 */ 566 initScenes:function () { 567 this._inScene.setPosition(-(cc.Director.getInstance().getWinSize().width - cc.ADJUST_FACTOR), 0); 568 }, 569 /** 570 * returns the action that will be performed by the incomming and outgoing scene 571 * @return {cc.MoveBy} 572 */ 573 action:function () { 574 return cc.MoveBy.create(this._duration, cc.p(cc.Director.getInstance().getWinSize().width - cc.ADJUST_FACTOR, 0)); 575 }, 576 577 /** 578 * @param {cc.ActionInterval} action 579 * @return {*} 580 */ 581 easeActionWithAction:function (action) { 582 return cc.EaseOut.create(action, 2.0); 583 } 584 }); 585 586 /** 587 * create a transition that a new scene is slided from left 588 * @param {Number} t time in seconds 589 * @param {cc.Scene} scene 590 * @return {cc.TransitionSlideInL} 591 * @example 592 * // Example 593 * var myTransition = cc.TransitionSlideInL.create(1.5, nextScene) 594 */ 595 cc.TransitionSlideInL.create = function (t, scene) { 596 var tempScene = new cc.TransitionSlideInL(); 597 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 598 return tempScene; 599 } 600 return null; 601 }; 602 603 /** 604 * Slide in the incoming scene from the right border. 605 * @class 606 * @extends cc.TransitionSlideInL 607 */ 608 cc.TransitionSlideInR = cc.TransitionSlideInL.extend(/** @lends cc.TransitionSlideInR# */{ 609 _sceneOrder:function () { 610 this._isInSceneOnTop = true; 611 }, 612 /** 613 * initializes the scenes 614 */ 615 initScenes:function () { 616 this._inScene.setPosition(cc.Director.getInstance().getWinSize().width - cc.ADJUST_FACTOR, 0); 617 }, 618 /** 619 * returns the action that will be performed by the incomming and outgoing scene 620 * @return {cc.MoveBy} 621 */ 622 action:function () { 623 return cc.MoveBy.create(this._duration, cc.p(-(cc.Director.getInstance().getWinSize().width - cc.ADJUST_FACTOR), 0)); 624 } 625 }); 626 627 /** 628 * create Slide in the incoming scene from the right border. 629 * @param {Number} t time in seconds 630 * @param {cc.Scene} scene 631 * @return {cc.TransitionSlideInR} 632 * @example 633 * // Example 634 * var myTransition = cc.TransitionSlideInR.create(1.5, nextScene) 635 */ 636 cc.TransitionSlideInR.create = function (t, scene) { 637 var tempScene = new cc.TransitionSlideInR(); 638 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 639 return tempScene; 640 } 641 return null; 642 }; 643 644 /** 645 * Slide in the incoming scene from the bottom border. 646 * @class 647 * @extends cc.TransitionSlideInL 648 */ 649 cc.TransitionSlideInB = cc.TransitionSlideInL.extend(/** @lends cc.TransitionSlideInB# */{ 650 _sceneOrder:function () { 651 this._isInSceneOnTop = false; 652 }, 653 654 /** 655 * initializes the scenes 656 */ 657 initScenes:function () { 658 this._inScene.setPosition(0, cc.Director.getInstance().getWinSize().height - cc.ADJUST_FACTOR); 659 }, 660 661 /** 662 * returns the action that will be performed by the incomming and outgoing scene 663 * @return {cc.MoveBy} 664 */ 665 action:function () { 666 return cc.MoveBy.create(this._duration, cc.p(0, -(cc.Director.getInstance().getWinSize().height - cc.ADJUST_FACTOR))); 667 } 668 }); 669 670 /** 671 * create a Slide in the incoming scene from the bottom border. 672 * @param {Number} t time in seconds 673 * @param {cc.Scene} scene 674 * @return {cc.TransitionSlideInB} 675 * @example 676 * // Example 677 * var myTransition = cc.TransitionSlideInB.create(1.5, nextScene) 678 */ 679 cc.TransitionSlideInB.create = function (t, scene) { 680 var tempScene = new cc.TransitionSlideInB(); 681 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 682 return tempScene; 683 } 684 return null; 685 }; 686 687 /** 688 * Slide in the incoming scene from the top border. 689 * @class 690 * @extends cc.TransitionSlideInL 691 */ 692 cc.TransitionSlideInT = cc.TransitionSlideInL.extend(/** @lends cc.TransitionSlideInT# */{ 693 _sceneOrder:function () { 694 this._isInSceneOnTop = true; 695 }, 696 697 /** 698 * initializes the scenes 699 */ 700 initScenes:function () { 701 this._inScene.setPosition(0, -(cc.Director.getInstance().getWinSize().height - cc.ADJUST_FACTOR)); 702 }, 703 704 /** 705 * returns the action that will be performed by the incomming and outgoing scene 706 * @return {cc.MoveBy} 707 */ 708 action:function () { 709 return cc.MoveBy.create(this._duration, cc.p(0, cc.Director.getInstance().getWinSize().height - cc.ADJUST_FACTOR)); 710 } 711 }); 712 713 /** 714 * create a Slide in the incoming scene from the top border. 715 * @param {Number} t time in seconds 716 * @param {cc.Scene} scene 717 * @return {cc.TransitionSlideInT} 718 * @example 719 * // Example 720 * var myTransition = cc.TransitionSlideInT.create(1.5, nextScene) 721 */ 722 cc.TransitionSlideInT.create = function (t, scene) { 723 var tempScene = new cc.TransitionSlideInT(); 724 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 725 return tempScene; 726 } 727 return null; 728 }; 729 730 /** 731 * Shrink the outgoing scene while grow the incoming scene 732 * @class 733 * @extends cc.TransitionScene 734 */ 735 cc.TransitionShrinkGrow = cc.TransitionScene.extend(/** @lends cc.TransitionShrinkGrow# */{ 736 737 /** 738 * Custom on enter 739 */ 740 onEnter:function () { 741 cc.TransitionScene.prototype.onEnter.call(this); 742 743 this._inScene.setScale(0.001); 744 this._outScene.setScale(1.0); 745 746 this._inScene.setAnchorPoint(2 / 3.0, 0.5); 747 this._outScene.setAnchorPoint(1 / 3.0, 0.5); 748 749 var scaleOut = cc.ScaleTo.create(this._duration, 0.01); 750 var scaleIn = cc.ScaleTo.create(this._duration, 1.0); 751 752 this._inScene.runAction(this.easeActionWithAction(scaleIn)); 753 this._outScene.runAction( 754 cc.Sequence.create(this.easeActionWithAction(scaleOut), cc.CallFunc.create(this.finish, this)) 755 ); 756 }, 757 758 /** 759 * @param action 760 * @return {cc.EaseOut} 761 */ 762 easeActionWithAction:function (action) { 763 return cc.EaseOut.create(action, 2.0); 764 } 765 }); 766 767 /** 768 * Shrink the outgoing scene while grow the incoming scene 769 * @param {Number} t time in seconds 770 * @param {cc.Scene} scene 771 * @return {cc.TransitionShrinkGrow} 772 * @example 773 * // Example 774 * var myTransition = cc.TransitionShrinkGrow.create(1.5, nextScene) 775 */ 776 cc.TransitionShrinkGrow.create = function (t, scene) { 777 var tempScene = new cc.TransitionShrinkGrow(); 778 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 779 return tempScene; 780 } 781 return null; 782 }; 783 784 /** 785 * Flips the screen horizontally.<br/> 786 * The front face is the outgoing scene and the back face is the incoming scene. 787 * @class 788 * @extends cc.TransitionSceneOriented 789 */ 790 cc.TransitionFlipX = cc.TransitionSceneOriented.extend(/** @lends cc.TransitionFlipX# */{ 791 792 /** 793 * custom on enter 794 */ 795 onEnter:function () { 796 cc.TransitionScene.prototype.onEnter.call(this); 797 798 var inA, outA; 799 this._inScene.setVisible(false); 800 801 var inDeltaZ, inAngleZ, outDeltaZ, outAngleZ; 802 803 if (this._orientation === cc.TRANSITION_ORIENTATION_RIGHT_OVER) { 804 inDeltaZ = 90; 805 inAngleZ = 270; 806 outDeltaZ = 90; 807 outAngleZ = 0; 808 } else { 809 inDeltaZ = -90; 810 inAngleZ = 90; 811 outDeltaZ = -90; 812 outAngleZ = 0; 813 } 814 815 inA = cc.Sequence.create( 816 cc.DelayTime.create(this._duration / 2), cc.Show.create(), 817 cc.OrbitCamera.create(this._duration / 2, 1, 0, inAngleZ, inDeltaZ, 0, 0), 818 cc.CallFunc.create(this.finish, this) 819 ); 820 821 outA = cc.Sequence.create( 822 cc.OrbitCamera.create(this._duration / 2, 1, 0, outAngleZ, outDeltaZ, 0, 0), 823 cc.Hide.create(), cc.DelayTime.create(this._duration / 2) 824 ); 825 826 this._inScene.runAction(inA); 827 this._outScene.runAction(outA); 828 } 829 }); 830 831 /** 832 * Flips the screen horizontally.<br/> 833 * The front face is the outgoing scene and the back face is the incoming scene. 834 * @param {Number} t time in seconds 835 * @param {cc.Scene} scene 836 * @param {cc.TRANSITION_ORIENTATION_LEFT_OVER|cc.TRANSITION_ORIENTATION_RIGHT_OVER|cc.TRANSITION_ORIENTATION_UP_OVER|cc.TRANSITION_ORIENTATION_DOWN_OVER} o 837 * @return {cc.TransitionFlipX} 838 * @example 839 * // Example 840 * var myTransition = cc.TransitionFlipX.create(1.5, nextScene) //default is cc.TRANSITION_ORIENTATION_RIGHT_OVER 841 * 842 * //OR 843 * var myTransition = cc.TransitionFlipX.create(1.5, nextScene, cc.TRANSITION_ORIENTATION_UP_OVER) 844 */ 845 cc.TransitionFlipX.create = function (t, scene, o) { 846 if (o == null) 847 o = cc.TRANSITION_ORIENTATION_RIGHT_OVER; 848 849 var tempScene = new cc.TransitionFlipX(); 850 tempScene.initWithDuration(t, scene, o); 851 return tempScene; 852 }; 853 854 /** 855 * Flips the screen vertically.<br/> 856 * The front face is the outgoing scene and the back face is the incoming scene. 857 * @class 858 * @extends cc.TransitionSceneOriented 859 */ 860 cc.TransitionFlipY = cc.TransitionSceneOriented.extend(/** @lends cc.TransitionFlipY# */{ 861 862 /** 863 * custom on enter 864 */ 865 onEnter:function () { 866 cc.TransitionScene.prototype.onEnter.call(this); 867 868 var inA, outA; 869 this._inScene.setVisible(false); 870 871 var inDeltaZ, inAngleZ, outDeltaZ, outAngleZ; 872 873 if (this._orientation == cc.TRANSITION_ORIENTATION_UP_OVER) { 874 inDeltaZ = 90; 875 inAngleZ = 270; 876 outDeltaZ = 90; 877 outAngleZ = 0; 878 } else { 879 inDeltaZ = -90; 880 inAngleZ = 90; 881 outDeltaZ = -90; 882 outAngleZ = 0; 883 } 884 885 inA = cc.Sequence.create( 886 cc.DelayTime.create(this._duration / 2), cc.Show.create(), 887 cc.OrbitCamera.create(this._duration / 2, 1, 0, inAngleZ, inDeltaZ, 90, 0), 888 cc.CallFunc.create(this.finish, this) 889 ); 890 outA = cc.Sequence.create( 891 cc.OrbitCamera.create(this._duration / 2, 1, 0, outAngleZ, outDeltaZ, 90, 0), 892 cc.Hide.create(), cc.DelayTime.create(this._duration / 2) 893 ); 894 895 this._inScene.runAction(inA); 896 this._outScene.runAction(outA); 897 } 898 }); 899 900 /** 901 * Flips the screen vertically.<br/> 902 * The front face is the outgoing scene and the back face is the incoming scene. 903 * @param {Number} t time in seconds 904 * @param {cc.Scene} scene 905 * @param {cc.TRANSITION_ORIENTATION_LEFT_OVER|cc.TRANSITION_ORIENTATION_RIGHT_OVER|cc.TRANSITION_ORIENTATION_UP_OVER|cc.TRANSITION_ORIENTATION_DOWN_OVER} o 906 * @return {cc.TransitionFlipY} 907 * @example 908 * // Example 909 * var myTransition = cc.TransitionFlipY.create(1.5, nextScene)//default is cc.TRANSITION_ORIENTATION_UP_OVER 910 * 911 * //OR 912 * var myTransition = cc.TransitionFlipY.create(1.5, nextScene, cc.TRANSITION_ORIENTATION_RIGHT_OVER) 913 */ 914 cc.TransitionFlipY.create = function (t, scene, o) { 915 if (o == null) 916 o = cc.TRANSITION_ORIENTATION_UP_OVER; 917 918 var tempScene = new cc.TransitionFlipY(); 919 tempScene.initWithDuration(t, scene, o); 920 921 return tempScene; 922 }; 923 924 /** 925 * Flips the screen half horizontally and half vertically.<br/> 926 * The front face is the outgoing scene and the back face is the incoming scene. 927 * @class 928 * @extends cc.TransitionSceneOriented 929 */ 930 cc.TransitionFlipAngular = cc.TransitionSceneOriented.extend(/** @lends cc.TransitionFlipAngular# */{ 931 /** 932 * custom on enter 933 */ 934 onEnter:function () { 935 cc.TransitionScene.prototype.onEnter.call(this); 936 937 var inA, outA; 938 this._inScene.setVisible(false); 939 940 var inDeltaZ, inAngleZ, outDeltaZ, outAngleZ; 941 942 if (this._orientation === cc.TRANSITION_ORIENTATION_RIGHT_OVER) { 943 inDeltaZ = 90; 944 inAngleZ = 270; 945 outDeltaZ = 90; 946 outAngleZ = 0; 947 } else { 948 inDeltaZ = -90; 949 inAngleZ = 90; 950 outDeltaZ = -90; 951 outAngleZ = 0; 952 } 953 954 inA = cc.Sequence.create( 955 cc.DelayTime.create(this._duration / 2), cc.Show.create(), 956 cc.OrbitCamera.create(this._duration / 2, 1, 0, inAngleZ, inDeltaZ, -45, 0), 957 cc.CallFunc.create(this.finish, this) 958 ); 959 outA = cc.Sequence.create( 960 cc.OrbitCamera.create(this._duration / 2, 1, 0, outAngleZ, outDeltaZ, 45, 0), 961 cc.Hide.create(), cc.DelayTime.create(this._duration / 2) 962 ); 963 964 this._inScene.runAction(inA); 965 this._outScene.runAction(outA); 966 } 967 }); 968 969 /** 970 * Flips the screen half horizontally and half vertically.<br/> 971 * The front face is the outgoing scene and the back face is the incoming scene. 972 * @param {Number} t time in seconds 973 * @param {cc.Scene} scene 974 * @param {cc.TRANSITION_ORIENTATION_LEFT_OVER|cc.TRANSITION_ORIENTATION_RIGHT_OVER|cc.TRANSITION_ORIENTATION_UP_OVER|cc.TRANSITION_ORIENTATION_DOWN_OVER} o 975 * @return {cc.TransitionFlipAngular} 976 * @example 977 * // Example 978 * var myTransition = cc.TransitionFlipAngular.create(1.5, nextScene)//default is cc.TRANSITION_ORIENTATION_RIGHT_OVER 979 * 980 * //or 981 * var myTransition = cc.TransitionFlipAngular.create(1.5, nextScene, cc.TRANSITION_ORIENTATION_DOWN_OVER) 982 */ 983 cc.TransitionFlipAngular.create = function (t, scene, o) { 984 if (o == null) 985 o = cc.TRANSITION_ORIENTATION_RIGHT_OVER; 986 987 var tempScene = new cc.TransitionFlipAngular(); 988 tempScene.initWithDuration(t, scene, o); 989 990 return tempScene; 991 }; 992 993 /** 994 * Flips the screen horizontally doing a zoom out/in<br/> 995 * The front face is the outgoing scene and the back face is the incoming scene. 996 * @class 997 * @extends cc.TransitionSceneOriented 998 */ 999 cc.TransitionZoomFlipX = cc.TransitionSceneOriented.extend(/** @lends cc.TransitionZoomFlipX# */{ 1000 1001 /** 1002 * custom on enter 1003 */ 1004 onEnter:function () { 1005 cc.TransitionScene.prototype.onEnter.call(this); 1006 1007 var inA, outA; 1008 this._inScene.setVisible(false); 1009 1010 var inDeltaZ, inAngleZ, outDeltaZ, outAngleZ; 1011 1012 if (this._orientation === cc.TRANSITION_ORIENTATION_RIGHT_OVER) { 1013 inDeltaZ = 90; 1014 inAngleZ = 270; 1015 outDeltaZ = 90; 1016 outAngleZ = 0; 1017 } else { 1018 inDeltaZ = -90; 1019 inAngleZ = 90; 1020 outDeltaZ = -90; 1021 outAngleZ = 0; 1022 } 1023 1024 inA = cc.Sequence.create( 1025 cc.DelayTime.create(this._duration / 2), 1026 cc.Spawn.create( 1027 cc.OrbitCamera.create(this._duration / 2, 1, 0, inAngleZ, inDeltaZ, 0, 0), 1028 cc.ScaleTo.create(this._duration / 2, 1), cc.Show.create()), 1029 cc.CallFunc.create(this.finish, this) 1030 ); 1031 outA = cc.Sequence.create( 1032 cc.Spawn.create( 1033 cc.OrbitCamera.create(this._duration / 2, 1, 0, outAngleZ, outDeltaZ, 0, 0), 1034 cc.ScaleTo.create(this._duration / 2, 0.5)), 1035 cc.Hide.create(), 1036 cc.DelayTime.create(this._duration / 2) 1037 ); 1038 1039 this._inScene.setScale(0.5); 1040 this._inScene.runAction(inA); 1041 this._outScene.runAction(outA); 1042 } 1043 }); 1044 1045 /** 1046 * Flips the screen horizontally doing a zoom out/in<br/> 1047 * The front face is the outgoing scene and the back face is the incoming scene. 1048 * @param {Number} t time in seconds 1049 * @param {cc.Scene} scene 1050 * @param {cc.TRANSITION_ORIENTATION_LEFT_OVER|cc.TRANSITION_ORIENTATION_RIGHT_OVER|cc.TRANSITION_ORIENTATION_UP_OVER|cc.TRANSITION_ORIENTATION_DOWN_OVER} o 1051 * @return {cc.TransitionZoomFlipX} 1052 * @example 1053 * // Example 1054 * var myTransition = cc.TransitionZoomFlipX.create(1.5, nextScene)//default is cc.TRANSITION_ORIENTATION_RIGHT_OVER 1055 * 1056 * //OR 1057 * var myTransition = cc.TransitionZoomFlipX.create(1.5, nextScene, cc.TRANSITION_ORIENTATION_DOWN_OVER) 1058 */ 1059 cc.TransitionZoomFlipX.create = function (t, scene, o) { 1060 if (o == null) 1061 o = cc.TRANSITION_ORIENTATION_RIGHT_OVER; 1062 1063 var tempScene = new cc.TransitionZoomFlipX(); 1064 tempScene.initWithDuration(t, scene, o); 1065 1066 return tempScene; 1067 }; 1068 1069 /** 1070 * Flips the screen vertically doing a little zooming out/in<br/> 1071 * The front face is the outgoing scene and the back face is the incoming scene. 1072 * @class 1073 * @extends cc.TransitionSceneOriented 1074 */ 1075 cc.TransitionZoomFlipY = cc.TransitionSceneOriented.extend(/** @lends cc.TransitionZoomFlipY# */{ 1076 1077 /** 1078 * custom on enter 1079 */ 1080 onEnter:function () { 1081 cc.TransitionScene.prototype.onEnter.call(this); 1082 1083 var inA, outA; 1084 this._inScene.setVisible(false); 1085 1086 var inDeltaZ, inAngleZ, outDeltaZ, outAngleZ; 1087 1088 if (this._orientation === cc.TRANSITION_ORIENTATION_UP_OVER) { 1089 inDeltaZ = 90; 1090 inAngleZ = 270; 1091 outDeltaZ = 90; 1092 outAngleZ = 0; 1093 } else { 1094 inDeltaZ = -90; 1095 inAngleZ = 90; 1096 outDeltaZ = -90; 1097 outAngleZ = 0; 1098 } 1099 1100 inA = cc.Sequence.create( 1101 cc.DelayTime.create(this._duration / 2), 1102 cc.Spawn.create( 1103 cc.OrbitCamera.create(this._duration / 2, 1, 0, inAngleZ, inDeltaZ, 90, 0), 1104 cc.ScaleTo.create(this._duration / 2, 1), cc.Show.create()), 1105 cc.CallFunc.create(this.finish, this)); 1106 1107 outA = cc.Sequence.create( 1108 cc.Spawn.create( 1109 cc.OrbitCamera.create(this._duration / 2, 1, 0, outAngleZ, outDeltaZ, 90, 0), 1110 cc.ScaleTo.create(this._duration / 2, 0.5)), 1111 cc.Hide.create(), cc.DelayTime.create(this._duration / 2)); 1112 1113 this._inScene.setScale(0.5); 1114 this._inScene.runAction(inA); 1115 this._outScene.runAction(outA); 1116 } 1117 }); 1118 1119 /** 1120 * Flips the screen vertically doing a little zooming out/in<br/> 1121 * The front face is the outgoing scene and the back face is the incoming scene. 1122 * @param {Number} t time in seconds 1123 * @param {cc.Scene} scene 1124 * @param {cc.TRANSITION_ORIENTATION_LEFT_OVER|cc.TRANSITION_ORIENTATION_RIGHT_OVER|cc.TRANSITION_ORIENTATION_UP_OVER|cc.TRANSITION_ORIENTATION_DOWN_OVER} o 1125 * @return {cc.TransitionZoomFlipY} 1126 * @example 1127 * // Example 1128 * var myTransition = cc.TransitionZoomFlipY.create(1.5, nextScene)//default is cc.TRANSITION_ORIENTATION_UP_OVER 1129 * 1130 * //OR 1131 * var myTransition = cc.TransitionZoomFlipY.create(1.5, nextScene, cc.TRANSITION_ORIENTATION_DOWN_OVER) 1132 */ 1133 cc.TransitionZoomFlipY.create = function (t, scene, o) { 1134 if (o == null) 1135 o = cc.TRANSITION_ORIENTATION_UP_OVER; 1136 1137 var tempScene = new cc.TransitionZoomFlipY(); 1138 tempScene.initWithDuration(t, scene, o); 1139 1140 return tempScene; 1141 }; 1142 1143 /** 1144 * Flips the screen half horizontally and half vertically doing a little zooming out/in.<br/> 1145 * The front face is the outgoing scene and the back face is the incoming scene. 1146 * @class 1147 * @extends cc.TransitionSceneOriented 1148 */ 1149 cc.TransitionZoomFlipAngular = cc.TransitionSceneOriented.extend(/** @lends cc.TransitionZoomFlipAngular# */{ 1150 1151 /** 1152 * custom on enter 1153 */ 1154 onEnter:function () { 1155 cc.TransitionScene.prototype.onEnter.call(this); 1156 1157 var inA, outA; 1158 this._inScene.setVisible(false); 1159 1160 var inDeltaZ, inAngleZ, outDeltaZ, outAngleZ; 1161 if (this._orientation === cc.TRANSITION_ORIENTATION_RIGHT_OVER) { 1162 inDeltaZ = 90; 1163 inAngleZ = 270; 1164 outDeltaZ = 90; 1165 outAngleZ = 0; 1166 } else { 1167 inDeltaZ = -90; 1168 inAngleZ = 90; 1169 outDeltaZ = -90; 1170 outAngleZ = 0; 1171 } 1172 1173 inA = cc.Sequence.create( 1174 cc.DelayTime.create(this._duration / 2), 1175 cc.Spawn.create( 1176 cc.OrbitCamera.create(this._duration / 2, 1, 0, inAngleZ, inDeltaZ, -45, 0), 1177 cc.ScaleTo.create(this._duration / 2, 1), cc.Show.create()), 1178 cc.Show.create(), 1179 cc.CallFunc.create(this.finish, this)); 1180 outA = cc.Sequence.create( 1181 cc.Spawn.create( 1182 cc.OrbitCamera.create(this._duration / 2, 1, 0, outAngleZ, outDeltaZ, 45, 0), 1183 cc.ScaleTo.create(this._duration / 2, 0.5)), 1184 cc.Hide.create(), cc.DelayTime.create(this._duration / 2)); 1185 1186 this._inScene.setScale(0.5); 1187 this._inScene.runAction(inA); 1188 this._outScene.runAction(outA); 1189 } 1190 }); 1191 1192 /** 1193 * Flips the screen half horizontally and half vertically doing a little zooming out/in.<br/> 1194 * The front face is the outgoing scene and the back face is the incoming scene. 1195 * @param {Number} t time in seconds 1196 * @param {cc.Scene} scene 1197 * @param {cc.TRANSITION_ORIENTATION_LEFT_OVER|cc.TRANSITION_ORIENTATION_RIGHT_OVER|cc.TRANSITION_ORIENTATION_UP_OVER|cc.TRANSITION_ORIENTATION_DOWN_OVER} o 1198 * @return {cc.TransitionZoomFlipAngular} 1199 * @example 1200 * // Example 1201 * var myTransition = cc.TransitionZoomFlipAngular.create(1.5, nextScene)//default is cc.TRANSITION_ORIENTATION_RIGHT_OVER 1202 * 1203 * //OR 1204 * var myTransition = cc.TransitionZoomFlipAngular.create(1.5, nextScene, cc.TRANSITION_ORIENTATION_DOWN_OVER) 1205 */ 1206 cc.TransitionZoomFlipAngular.create = function (t, scene, o) { 1207 if (o == null) 1208 o = cc.TRANSITION_ORIENTATION_RIGHT_OVER; 1209 1210 var tempScene = new cc.TransitionZoomFlipAngular(); 1211 tempScene.initWithDuration(t, scene, o); 1212 1213 return tempScene; 1214 }; 1215 1216 /** 1217 * Fade out the outgoing scene and then fade in the incoming scene. 1218 * @class 1219 * @extends cc.TransitionScene 1220 */ 1221 cc.TransitionFade = cc.TransitionScene.extend(/** @lends cc.TransitionFade# */{ 1222 _color:null, 1223 1224 /** 1225 * Constructor 1226 */ 1227 ctor:function () { 1228 cc.TransitionScene.prototype.ctor.call(this); 1229 this._color = new cc.Color4B() 1230 }, 1231 1232 /** 1233 * custom on enter 1234 */ 1235 onEnter:function () { 1236 cc.TransitionScene.prototype.onEnter.call(this); 1237 1238 var l = cc.LayerColor.create(this._color); 1239 this._inScene.setVisible(false); 1240 1241 this.addChild(l, 2, cc.SCENE_FADE); 1242 var f = this.getChildByTag(cc.SCENE_FADE); 1243 1244 var a = cc.Sequence.create( 1245 cc.FadeIn.create(this._duration / 2), 1246 cc.CallFunc.create(this.hideOutShowIn, this), //CCCallFunc.actionWithTarget:self selector:@selector(hideOutShowIn)], 1247 cc.FadeOut.create(this._duration / 2), 1248 cc.CallFunc.create(this.finish, this) //:self selector:@selector(finish)], 1249 ); 1250 f.runAction(a); 1251 }, 1252 1253 /** 1254 * custom on exit 1255 */ 1256 onExit:function () { 1257 cc.TransitionScene.prototype.onExit.call(this); 1258 this.removeChildByTag(cc.SCENE_FADE, false); 1259 }, 1260 1261 /** 1262 * initializes the transition with a duration and with an RGB color 1263 * @param {Number} t time in seconds 1264 * @param {cc.Scene} scene 1265 * @param {cc.Color3B} color 1266 * @return {Boolean} 1267 */ 1268 initWithDuration:function (t, scene, color) { 1269 color = color || cc.black(); 1270 if (cc.TransitionScene.prototype.initWithDuration.call(this, t, scene)) { 1271 this._color.r = color.r; 1272 this._color.g = color.g; 1273 this._color.b = color.b; 1274 this._color.a = 0; 1275 } 1276 return true; 1277 } 1278 }); 1279 1280 1281 /** 1282 * Fade out the outgoing scene and then fade in the incoming scene. 1283 * @param {Number} t time in seconds 1284 * @param {cc.Scene} scene 1285 * @param {cc.Color3B} color 1286 * @return {cc.TransitionFade} 1287 * @example 1288 * // Example 1289 * var myTransition = cc.TransitionFade.create(1.5, nextScene, cc.c3b(255,0,0))//fade to red 1290 */ 1291 cc.TransitionFade.create = function (t, scene, color) { 1292 var transition = new cc.TransitionFade(); 1293 transition.initWithDuration(t, scene, color); 1294 return transition; 1295 }; 1296 1297 /** 1298 * Cross fades two scenes using the cc.RenderTexture object. 1299 * @class 1300 * @extends cc.TransitionScene 1301 */ 1302 cc.TransitionCrossFade = cc.TransitionScene.extend(/** @lends cc.TransitionCrossFade# */{ 1303 /** 1304 * custom on enter 1305 */ 1306 onEnter:function () { 1307 cc.TransitionScene.prototype.onEnter.call(this); 1308 1309 // create a transparent color layer 1310 // in which we are going to add our rendertextures 1311 var color = new cc.Color4B(0, 0, 0, 0); 1312 var winSize = cc.Director.getInstance().getWinSize(); 1313 var layer = cc.LayerColor.create(color); 1314 1315 // create the first render texture for inScene 1316 var inTexture = cc.RenderTexture.create(winSize.width, winSize.height); 1317 1318 if (null == inTexture) 1319 return; 1320 1321 inTexture.getSprite().setAnchorPoint(0.5, 0.5); 1322 inTexture.setPosition(winSize.width / 2, winSize.height / 2); 1323 inTexture.setAnchorPoint(0.5, 0.5); 1324 1325 // render inScene to its texturebuffer 1326 inTexture.begin(); 1327 this._inScene.visit(); 1328 inTexture.end(); 1329 1330 // create the second render texture for outScene 1331 var outTexture = cc.RenderTexture.create(winSize.width, winSize.height); 1332 outTexture.getSprite().setAnchorPoint(0.5, 0.5); 1333 outTexture.setPosition(winSize.width / 2, winSize.height / 2); 1334 outTexture.setAnchorPoint(0.5, 0.5); 1335 1336 // render outScene to its texturebuffer 1337 outTexture.begin(); 1338 this._outScene.visit(); 1339 outTexture.end(); 1340 1341 inTexture.getSprite().setBlendFunc(gl.ONE, gl.ONE); // inScene will lay on background and will not be used with alpha 1342 outTexture.getSprite().setBlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); // we are going to blend outScene via alpha 1343 1344 // add render textures to the layer 1345 layer.addChild(inTexture); 1346 layer.addChild(outTexture); 1347 1348 // initial opacity: 1349 inTexture.getSprite().setOpacity(255); 1350 outTexture.getSprite().setOpacity(255); 1351 1352 // create the blend action 1353 var layerAction = cc.Sequence.create( 1354 cc.FadeTo.create(this._duration, 0), cc.CallFunc.create(this.hideOutShowIn, this), 1355 cc.CallFunc.create(this.finish, this) 1356 ); 1357 1358 // run the blend action 1359 outTexture.getSprite().runAction(layerAction); 1360 1361 // add the layer (which contains our two rendertextures) to the scene 1362 this.addChild(layer, 2, cc.SCENE_FADE); 1363 }, 1364 1365 /** 1366 * custom on exit 1367 */ 1368 onExit:function () { 1369 this.removeChildByTag(cc.SCENE_FADE, false); 1370 cc.TransitionScene.prototype.onExit.call(this); 1371 }, 1372 1373 /** 1374 * overide draw 1375 */ 1376 draw:function () { 1377 // override draw since both scenes (textures) are rendered in 1 scene 1378 } 1379 }); 1380 1381 /** 1382 * Cross fades two scenes using the cc.RenderTexture object. 1383 * @param {Number} t time in seconds 1384 * @param {cc.Scene} scene 1385 * @return {cc.TransitionCrossFade} 1386 * @example 1387 * // Example 1388 * var myTransition = cc.TransitionCrossFade.create(1.5, nextScene) 1389 */ 1390 cc.TransitionCrossFade.create = function (t, scene) { 1391 var Transition = new cc.TransitionCrossFade(); 1392 Transition.initWithDuration(t, scene); 1393 return Transition; 1394 }; 1395 1396 /** 1397 * Turn off the tiles of the outgoing scene in random order 1398 * @class 1399 * @extends cc.TransitionScene 1400 */ 1401 cc.TransitionTurnOffTiles = cc.TransitionScene.extend(/** @lends cc.TransitionTurnOffTiles# */{ 1402 _sceneOrder:function () { 1403 this._isInSceneOnTop = false; 1404 }, 1405 1406 /** 1407 * custom on enter 1408 */ 1409 onEnter:function () { 1410 cc.TransitionScene.prototype.onEnter.call(this); 1411 var winSize = cc.Director.getInstance().getWinSize(); 1412 var aspect = winSize.width / winSize.height; 1413 var x = 0 | (12 * aspect); 1414 var y = 12; 1415 var toff = cc.TurnOffTiles.create(this._duration, cc.size(x, y)); 1416 var action = this.easeActionWithAction(toff); 1417 this._outScene.runAction(cc.Sequence.create(action, cc.CallFunc.create(this.finish, this), cc.StopGrid.create())); 1418 }, 1419 1420 /** 1421 * @param {cc.ActionInterval} action 1422 * @return {cc.ActionInterval} 1423 */ 1424 easeActionWithAction:function (action) { 1425 return action; 1426 } 1427 }); 1428 1429 /** 1430 * Turn off the tiles of the outgoing scene in random order 1431 * @param {Number} t time in seconds 1432 * @param {cc.Scene} scene 1433 * @return {cc.TransitionTurnOffTiles} 1434 * @example 1435 * // Example 1436 * var myTransition = cc.TransitionTurnOffTiles.create(1.5, nextScene) 1437 */ 1438 cc.TransitionTurnOffTiles.create = function (t, scene) { 1439 var tempScene = new cc.TransitionTurnOffTiles(); 1440 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 1441 return tempScene; 1442 } 1443 return null; 1444 }; 1445 1446 /** 1447 * The odd columns goes upwards while the even columns goes downwards. 1448 * @class 1449 * @extends cc.TransitionScene 1450 */ 1451 cc.TransitionSplitCols = cc.TransitionScene.extend(/** @lends cc.TransitionSplitCols# */{ 1452 1453 /** 1454 * custom on enter 1455 */ 1456 onEnter:function () { 1457 cc.TransitionScene.prototype.onEnter.call(this); 1458 this._inScene.setVisible(false); 1459 1460 var split = this.action(); 1461 var seq = cc.Sequence.create( 1462 split, cc.CallFunc.create(this.hideOutShowIn, this), split.reverse()); 1463 1464 this.runAction( 1465 cc.Sequence.create(this.easeActionWithAction(seq), cc.CallFunc.create(this.finish, this), cc.StopGrid.create()) 1466 ); 1467 }, 1468 1469 /** 1470 * @param {cc.ActionInterval} action 1471 * @return {cc.EaseInOut} 1472 */ 1473 easeActionWithAction:function (action) { 1474 return cc.EaseInOut.create(action, 3.0); 1475 }, 1476 1477 /** 1478 * @return {*} 1479 */ 1480 action:function () { 1481 return cc.SplitCols.create(this._duration / 2.0, 3); 1482 } 1483 }); 1484 1485 /** 1486 * The odd columns goes upwards while the even columns goes downwards. 1487 * @param {Number} t time in seconds 1488 * @param {cc.Scene} scene 1489 * @return {cc.TransitionSplitCols} 1490 * @example 1491 * // Example 1492 * var myTransition = cc.TransitionSplitCols.create(1.5, nextScene) 1493 */ 1494 cc.TransitionSplitCols.create = function (t, scene) { 1495 var tempScene = new cc.TransitionSplitCols(); 1496 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 1497 return tempScene; 1498 } 1499 return null; 1500 }; 1501 1502 /** 1503 * The odd rows goes to the left while the even rows goes to the right. 1504 * @class 1505 * @extends cc.TransitionSplitCols 1506 */ 1507 cc.TransitionSplitRows = cc.TransitionSplitCols.extend(/** @lends cc.TransitionSplitRows# */{ 1508 /** 1509 * @return {*} 1510 */ 1511 action:function () { 1512 return cc.SplitRows.create(this._duration / 2.0, 3); 1513 } 1514 }); 1515 1516 /** 1517 * The odd rows goes to the left while the even rows goes to the right. 1518 * @param {Number} t time in seconds 1519 * @param {cc.Scene} scene 1520 * @return {cc.TransitionSplitRows} 1521 * @example 1522 * // Example 1523 * var myTransition = cc.TransitionSplitRows.create(1.5, nextScene) 1524 */ 1525 cc.TransitionSplitRows.create = function (t, scene) { 1526 var tempScene = new cc.TransitionSplitRows(); 1527 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 1528 return tempScene; 1529 } 1530 return null; 1531 }; 1532 1533 /** 1534 * Fade the tiles of the outgoing scene from the left-bottom corner the to top-right corner. 1535 * @class 1536 * @extends cc.TransitionScene 1537 */ 1538 cc.TransitionFadeTR = cc.TransitionScene.extend(/** @lends cc.TransitionFadeTR# */{ 1539 _sceneOrder:function () { 1540 this._isInSceneOnTop = false; 1541 }, 1542 1543 /** 1544 * Custom on enter 1545 */ 1546 onEnter:function () { 1547 cc.TransitionScene.prototype.onEnter.call(this); 1548 1549 var winSize = cc.Director.getInstance().getWinSize(); 1550 var aspect = winSize.width / winSize.height; 1551 var x = 0 | (12 * aspect); 1552 var y = 12; 1553 1554 var action = this.actionWithSize(cc.size(x, y)); 1555 this._outScene.runAction( 1556 cc.Sequence.create(this.easeActionWithAction(action), cc.CallFunc.create(this.finish, this), 1557 cc.StopGrid.create()) 1558 ); 1559 }, 1560 1561 /** 1562 * @param {cc.ActionInterval} action 1563 * @return {cc.ActionInterval} 1564 */ 1565 easeActionWithAction:function (action) { 1566 return action; 1567 }, 1568 1569 /** 1570 * @param {cc.Size} size 1571 * @return {*} 1572 */ 1573 actionWithSize:function (size) { 1574 return cc.FadeOutTRTiles.create(this._duration, size); 1575 } 1576 }); 1577 1578 /** 1579 * Fade the tiles of the outgoing scene from the left-bottom corner the to top-right corner. 1580 * @param {Number} t time in seconds 1581 * @param {cc.Scene} scene 1582 * @return {cc.TransitionFadeTR} 1583 * @example 1584 * // Example 1585 * var myTransition = cc.TransitionFadeTR.create(1.5, nextScene) 1586 */ 1587 cc.TransitionFadeTR.create = function (t, scene) { 1588 var tempScene = new cc.TransitionFadeTR(); 1589 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) 1590 return tempScene; 1591 return null; 1592 }; 1593 1594 /** 1595 * Fade the tiles of the outgoing scene from the top-right corner to the bottom-left corner. 1596 * @class 1597 * @extends cc.TransitionFadeTR 1598 */ 1599 cc.TransitionFadeBL = cc.TransitionFadeTR.extend(/** @lends cc.TransitionFadeBL# */{ 1600 1601 /** 1602 * @param {cc.Size} size 1603 * @return {*} 1604 */ 1605 actionWithSize:function (size) { 1606 return cc.FadeOutBLTiles.create(this._duration, size); 1607 } 1608 }); 1609 1610 /** 1611 * Fade the tiles of the outgoing scene from the top-right corner to the bottom-left corner. 1612 * @param {Number} t time in seconds 1613 * @param {cc.Scene} scene 1614 * @return {cc.TransitionFadeBL} 1615 * @example 1616 * // Example 1617 * var myTransition = cc.TransitionFadeBL.create(1.5, nextScene) 1618 */ 1619 cc.TransitionFadeBL.create = function (t, scene) { 1620 var tempScene = new cc.TransitionFadeBL(); 1621 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) 1622 return tempScene; 1623 return null; 1624 }; 1625 1626 /** 1627 * Fade the tiles of the outgoing scene from the top-right corner to the bottom-left corner. 1628 * @class 1629 * @extends cc.TransitionFadeTR 1630 */ 1631 cc.TransitionFadeUp = cc.TransitionFadeTR.extend(/** @lends cc.TransitionFadeUp# */{ 1632 1633 /** 1634 * @param {cc.Size} size 1635 * @return {*} 1636 */ 1637 actionWithSize:function (size) { 1638 return cc.FadeOutUpTiles.create(this._duration, size); 1639 } 1640 }); 1641 1642 /** 1643 * Fade the tiles of the outgoing scene from the top-right corner to the bottom-left corner. 1644 * @param {Number} t time in seconds 1645 * @param {cc.Scene} scene 1646 * @return {cc.TransitionFadeUp} 1647 * @example 1648 * // Example 1649 * var myTransition = cc.TransitionFadeUp.create(1.5, nextScene) 1650 */ 1651 cc.TransitionFadeUp.create = function (t, scene) { 1652 var tempScene = new cc.TransitionFadeUp(); 1653 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 1654 return tempScene; 1655 } 1656 return null; 1657 }; 1658 1659 /** 1660 * Fade the tiles of the outgoing scene from the top to the bottom. 1661 * @class 1662 * @extends cc.TransitionFadeTR 1663 */ 1664 cc.TransitionFadeDown = cc.TransitionFadeTR.extend(/** @lends cc.TransitionFadeDown# */{ 1665 1666 /** 1667 * @param {cc.Size} size 1668 * @return {*} 1669 */ 1670 actionWithSize:function (size) { 1671 return cc.FadeOutDownTiles.create( this._duration, size); 1672 } 1673 }); 1674 1675 /** 1676 * Fade the tiles of the outgoing scene from the top to the bottom. 1677 * @param {Number} t time in seconds 1678 * @param {cc.Scene} scene 1679 * @return {cc.TransitionFadeDown} 1680 * @example 1681 * // Example 1682 * var myTransition = cc.TransitionFadeDown.create(1.5, nextScene) 1683 */ 1684 cc.TransitionFadeDown.create = function (t, scene) { 1685 var tempScene = new cc.TransitionFadeDown(); 1686 if ((tempScene != null) && (tempScene.initWithDuration(t, scene))) { 1687 return tempScene; 1688 } 1689 return null; 1690 }; 1691