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 * Base class for Easing actions 29 * @class 30 * @extends cc.ActionInterval 31 */ 32 33 cc.ActionEase = cc.ActionInterval.extend(/** @lends cc.ActionEase# */{ 34 /** initializes the action 35 * @param {cc.ActionInterval} action 36 * @return {Boolean} 37 */ 38 initWithAction:function (action) { 39 cc.Assert(action != null, ""); 40 41 if (this.initWithDuration(action.getDuration())) { 42 this._other = action; 43 return true; 44 } 45 return false; 46 }, 47 48 /** 49 * @param {cc.Node} target 50 */ 51 startWithTarget:function (target) { 52 cc.ActionInterval.prototype.startWithTarget.call(this, target); 53 this._other.startWithTarget(this._target); 54 }, 55 56 /** 57 * Stop the action. 58 */ 59 stop:function () { 60 this._other.stop(); 61 this._super(); 62 }, 63 64 /** 65 * @param {Number} time1 66 */ 67 update:function (time1) { 68 this._other.update(time1); 69 }, 70 71 /** 72 * @return {cc.ActionInterval} 73 */ 74 reverse:function () { 75 return cc.ActionEase.create(this._other.reverse()); 76 }, 77 78 _other:null 79 }); 80 81 /** creates the action of ActionEase 82 * @param {cc.ActionInterval} action 83 * @return {cc.ActionEase} 84 * @example 85 * // example 86 * var moveEase = cc.ActionEase.create(action); 87 */ 88 cc.ActionEase.create = function (action) { 89 var ret = new cc.ActionEase(); 90 if (ret) { 91 ret.initWithAction(action); 92 } 93 return ret; 94 }; 95 96 /** 97 * Base class for Easing actions with rate parameters 98 * @class 99 * @extends cc.ActionEase 100 */ 101 cc.EaseRateAction = cc.ActionEase.extend(/** @lends cc.EaseRateAction# */{ 102 103 /** set rate value for the actions 104 * @param {Number} rate 105 */ 106 setRate:function (rate) { 107 this._rate = rate; 108 }, 109 110 /** get rate value for the actions 111 * @return {Number} 112 */ 113 getRate:function () { 114 return this._rate; 115 }, 116 117 /** 118 * Initializes the action with the inner action and the rate parameter 119 * @param {cc.ActionInterval} action 120 * @param {Number} rate 121 * @return {Boolean} 122 */ 123 initWithAction:function (action, rate) { 124 if (this._super(action)) { 125 this._rate = rate; 126 return true; 127 } 128 return false; 129 }, 130 131 /** 132 * @return {cc.ActionInterval} 133 */ 134 reverse:function () { 135 return cc.EaseRateAction.create(this._other.reverse(), 1 / this._rate); 136 }, 137 138 _rate:null 139 }); 140 141 /** Creates the action with the inner action and the rate parameter 142 * @param {cc.ActionInterval} action 143 * @param {Number} rate 144 * @return {cc.EaseRateAction} 145 * @example 146 * // example 147 * var moveEaseRateAction = cc.EaseRateAction.create(action, 3.0); 148 */ 149 cc.EaseRateAction.create = function (action, rate) { 150 var ret = new cc.EaseRateAction(); 151 if (ret) { 152 ret.initWithAction(action, rate); 153 } 154 return ret; 155 }; 156 157 /** 158 * cc.EaseIn action with a rate 159 * @class 160 * @extends cc.EaseRateAction 161 */ 162 cc.EaseIn = cc.EaseRateAction.extend(/** @lends cc.EaseIn# */{ 163 /** 164 * @param {Number} time1 165 */ 166 update:function (time1) { 167 this._other.update(Math.pow(time1, this._rate)); 168 }, 169 170 /** 171 * @return {cc.ActionInterval} 172 */ 173 reverse:function () { 174 return cc.EaseIn.create(this._other.reverse(), 1 / this._rate); 175 } 176 }); 177 178 /** Creates the action with the inner action and the rate parameter 179 * @param {cc.ActionInterval} action 180 * @param {Number} rate 181 * @return {cc.EaseIn} 182 * @example 183 * // example 184 * var moveEaseIn = cc.EaseIn.create(action, 3.0); 185 */ 186 cc.EaseIn.create = function (action, rate) { 187 var ret = new cc.EaseIn(); 188 if (ret) { 189 ret.initWithAction(action, rate); 190 } 191 return ret; 192 }; 193 /** 194 * cc.EaseOut action with a rate 195 * @class 196 * @extends cc.EaseRateAction 197 */ 198 cc.EaseOut = cc.EaseRateAction.extend(/** @lends cc.EaseOut# */{ 199 /** 200 * @param {Number} time1 201 */ 202 update:function (time1) { 203 this._other.update(Math.pow(time1, 1 / this._rate)); 204 }, 205 206 /** 207 * @return {cc.ActionInterval} 208 */ 209 reverse:function () { 210 return cc.EaseOut.create(this._other.reverse(), 1 / this._rate); 211 } 212 }); 213 214 /** Creates the action with the inner action and the rate parameter 215 * @param {cc.ActionInterval} action 216 * @param {Number} rate 217 * @return {cc.EaseOut} 218 * @example 219 * // example 220 * var moveEaseOut = cc.EaseOut.create(action, 3.0); 221 */ 222 cc.EaseOut.create = function (action, rate) { 223 var ret = new cc.EaseOut(); 224 if (ret) { 225 ret.initWithAction(action, rate); 226 } 227 return ret; 228 }; 229 230 /** 231 * cc.EaseInOut action with a rate 232 * @class 233 * @extends cc.EaseRateAction 234 */ 235 cc.EaseInOut = cc.EaseRateAction.extend(/** @lends cc.EaseInOut# */{ 236 237 /** 238 * @param {Number} time1 239 */ 240 update:function (time1) { 241 time1 *= 2; 242 if (time1 < 1) { 243 this._other.update(0.5 * Math.pow(time1, this._rate)); 244 } else { 245 this._other.update(1.0 - 0.5 * Math.pow(2 - time1, this._rate)); 246 } 247 }, 248 249 /** 250 * @return {cc.ActionInterval} 251 */ 252 reverse:function () { 253 return cc.EaseInOut.create(this._other.reverse(), this._rate); 254 } 255 }); 256 257 /** Creates the action with the inner action and the rate parameter 258 * @param {cc.ActionInterval} action 259 * @param {Number} rate 260 * @return {cc.EaseInOut} 261 * @example 262 * // example 263 * var moveEaseInOut = cc.EaseInOut.create(action, 3.0); 264 */ 265 cc.EaseInOut.create = function (action, rate) { 266 var ret = new cc.EaseInOut(); 267 if (ret) { 268 ret.initWithAction(action, rate); 269 } 270 return ret; 271 }; 272 /** 273 * cc.Ease Exponential In 274 * @class 275 * @extends cc.ActionEase 276 */ 277 cc.EaseExponentialIn = cc.ActionEase.extend(/** @lends cc.EaseExponentialIn# */{ 278 /** 279 * @param {Number} time1 280 */ 281 update:function (time1) { 282 this._other.update(time1 == 0 ? 0 : Math.pow(2, 10 * (time1 - 1)) - 0.001); 283 }, 284 285 /** 286 * @return {cc.ActionInterval} 287 */ 288 reverse:function () { 289 return cc.EaseExponentialOut.create(this._other.reverse()); 290 } 291 }); 292 293 /** creates the action 294 * @param {cc.ActionInterval} action 295 * @return {cc.EaseExponentialIn} 296 * @example 297 * // example 298 * var moveEaseExponentialIn = cc.EaseExponentialIn.create(action); 299 */ 300 cc.EaseExponentialIn.create = function (action) { 301 var ret = new cc.EaseExponentialIn(); 302 if (ret) { 303 ret.initWithAction(action); 304 } 305 return ret; 306 }; 307 /** 308 * Ease Exponential Out 309 * @class 310 * @extends cc.ActionEase 311 */ 312 cc.EaseExponentialOut = cc.ActionEase.extend(/** @lends cc.EaseExponentialOut# */{ 313 314 /** 315 * @param {Number} time1 316 */ 317 update:function (time1) { 318 this._other.update(time1 == 1 ? 1 : (-(Math.pow(2, -10 * time1 )) + 1)); 319 }, 320 321 /** 322 * @return {cc.ActionInterval} 323 */ 324 reverse:function () { 325 return cc.EaseExponentialIn.create(this._other.reverse()); 326 } 327 }); 328 329 /** creates the action 330 * @param {cc.ActionInterval} action 331 * @return {cc.EaseExponentialOut} 332 * @example 333 * // example 334 * var moveEaseExponentialOut = cc.EaseExponentialOut.create(action); 335 */ 336 cc.EaseExponentialOut.create = function (action) { 337 var ret = new cc.EaseExponentialOut(); 338 if (ret) { 339 ret.initWithAction(action); 340 } 341 return ret; 342 }; 343 344 /** 345 * Ease Exponential InOut 346 * @class 347 * @extends cc.ActionEase 348 */ 349 cc.EaseExponentialInOut = cc.ActionEase.extend(/** @lends cc.EaseExponentialInOut# */{ 350 /** 351 * @param {Number} time 352 */ 353 update:function (time) { 354 time /= 0.5; 355 if (time < 1) 356 time = 0.5 * Math.pow(2, 10 * (time - 1)); 357 else 358 time = 0.5 * (-Math.pow(2, -10 * (time - 1)) + 2); 359 360 this._other.update(time); 361 }, 362 363 /** 364 * @return {cc.EaseExponentialInOut} 365 */ 366 reverse:function () { 367 return cc.EaseExponentialInOut.create(this._other.reverse()); 368 } 369 }); 370 371 /** creates the action 372 * @param {cc.ActionInterval} action 373 * @return {cc.EaseExponentialInOut} 374 * @example 375 * // example 376 * var moveEaseExponentialInOut = cc.EaseExponentialInOut.create(action); 377 */ 378 cc.EaseExponentialInOut.create = function (action) { 379 var ret = new cc.EaseExponentialInOut(); 380 if (ret) { 381 ret.initWithAction(action); 382 } 383 return ret; 384 }; 385 386 387 /** 388 * Ease Sine In 389 * @class 390 * @extends cc.ActionEase 391 */ 392 cc.EaseSineIn = cc.ActionEase.extend(/** @lends cc.EaseSineIn# */{ 393 /** 394 * @param {Number} time1 395 */ 396 update:function (time1) { 397 this._other.update(-1 * Math.cos(time1 * Math.PI / 2) + 1); 398 }, 399 400 /** 401 * @return {cc.ActionInterval} 402 */ 403 reverse:function () { 404 return cc.EaseSineOut.create(this._other.reverse()); 405 } 406 }); 407 408 /** creates the action 409 * @param {cc.ActionInterval} action 410 * @return {cc.EaseSineIn} 411 * @example 412 * // example 413 * var moveSineIn = cc.EaseSineIn.create(action); 414 */ 415 cc.EaseSineIn.create = function (action) { 416 var ret = new cc.EaseSineIn(); 417 if (ret) { 418 ret.initWithAction(action); 419 } 420 return ret; 421 }; 422 /** 423 * Ease Sine Out 424 * @class 425 * @extends cc.ActionEase 426 */ 427 cc.EaseSineOut = cc.ActionEase.extend(/** @lends cc.EaseSineOut# */{ 428 /** 429 * @param {Number} time1 430 */ 431 update:function (time1) { 432 this._other.update(Math.sin(time1 * Math.PI / 2)); 433 }, 434 435 /** 436 * @return {cc.ActionInterval} 437 */ 438 reverse:function () { 439 return cc.EaseSineIn.create(this._other.reverse()); 440 } 441 }); 442 443 444 /** creates the action 445 * @param {cc.ActionInterval} action 446 * @return {cc.EaseSineOut} 447 * @example 448 * // example 449 * var moveEaseOut = cc.EaseSineOut.create(action); 450 */ 451 cc.EaseSineOut.create = function (action) { 452 var ret = new cc.EaseSineOut(); 453 if (ret) { 454 ret.initWithAction(action); 455 } 456 return ret; 457 }; 458 459 460 /** 461 * Ease Sine InOut 462 * @class 463 * @extends cc.ActionEase 464 */ 465 cc.EaseSineInOut = cc.ActionEase.extend(/** @lends cc.EaseSineInOut# */{ 466 467 /** 468 * @param {Number} time1 469 */ 470 update:function (time1) { 471 this._other.update(-0.5 * (Math.cos(Math.PI * time1) - 1)); 472 473 }, 474 475 /** 476 * @return {cc.ActionInterval} 477 */ 478 reverse:function () { 479 return cc.EaseSineInOut.create(this._other.reverse()); 480 } 481 }); 482 483 /** creates the action 484 * @param {cc.ActionInterval} action 485 * @return {cc.EaseSineInOut} 486 * @example 487 * // example 488 * var moveEaseSineInOut = cc.EaseSineInOut.create(action); 489 */ 490 cc.EaseSineInOut.create = function (action) { 491 var ret = new cc.EaseSineInOut(); 492 if (ret) { 493 ret.initWithAction(action); 494 } 495 return ret; 496 }; 497 498 /** 499 * Ease Elastic abstract class 500 * @class 501 * @extends cc.ActionEase 502 */ 503 cc.EaseElastic = cc.ActionEase.extend(/** @lends cc.EaseElastic# */{ 504 505 /** get period of the wave in radians. default is 0.3 506 * @return {Number} 507 */ 508 getPeriod:function () { 509 return this._period; 510 }, 511 512 /** set period of the wave in radians. 513 * @param {Number} period 514 */ 515 setPeriod:function (period) { 516 this._period = period; 517 }, 518 519 /** Initializes the action with the inner action and the period in radians (default is 0.3) 520 * @param {cc.ActionInterval} action 521 * @param {Number} period 522 * @return {Boolean} 523 */ 524 initWithAction:function (action, period) { 525 this._super(action); 526 this._period = (period == null) ? 3.0 : period; 527 return true; 528 }, 529 530 /** 531 * @return {Null} 532 */ 533 reverse:function () { 534 cc.Assert(0, "Override me"); 535 return null; 536 }, 537 538 _period:null 539 }); 540 541 /** Creates the action with the inner action and the period in radians (default is 0.3) 542 * @param {cc.ActionInterval} action 543 * @param {Number} period 544 * @return {cc.EaseElastic} 545 * @example 546 * // example 547 * var moveEaseElastic = cc.EaseElastic.create(action, 3.0); 548 */ 549 cc.EaseElastic.create = function (action, period) { 550 var ret = new cc.EaseElastic(); 551 if (ret) { 552 if (period == null) { 553 ret.initWithAction(action); 554 } else { 555 ret.initWithAction(action, period); 556 } 557 } 558 return ret; 559 }; 560 561 562 /** 563 * Ease Elastic In action. 564 * @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. 565 * @class 566 * @extends cc.EaseElastic 567 */ 568 cc.EaseElasticIn = cc.EaseElastic.extend(/** @lends cc.EaseElasticIn# */{ 569 /** 570 * @param {Number} time1 571 */ 572 update:function (time1) { 573 var newT = 0; 574 if (time1 == 0 || time1 == 1) { 575 newT = time1; 576 } else { 577 var s = this._period / 4; 578 time1 = time1 - 1; 579 newT = -Math.pow(2, 10 * time1) * Math.sin((time1 - s) * Math.PI * 2 / this._period); 580 } 581 582 this._other.update(newT); 583 }, 584 585 /** 586 * @return {cc.ActionInterval} 587 */ 588 reverse:function () { 589 return cc.EaseElasticOut.create(this._other.reverse(), this._period); 590 } 591 }); 592 593 594 /** Creates the action with the inner action and the period in radians (default is 0.3) 595 * @param {cc.ActionInterval} action 596 * @param {Number} period 597 * @return {cc.EaseElasticIn} 598 * @example 599 * // example 600 * var moveEaseElasticIn = cc.EaseElasticIn.create(action, 3.0); 601 */ 602 cc.EaseElasticIn.create = function (action, period) { 603 var ret = new cc.EaseElasticIn(); 604 if (ret) { 605 if (period == null) { 606 ret.initWithAction(action); 607 } else { 608 ret.initWithAction(action, period); 609 } 610 } 611 return ret; 612 }; 613 614 /** 615 * Ease Elastic Out action. 616 * @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. 617 * @class 618 * @extends cc.EaseElastic 619 */ 620 cc.EaseElasticOut = cc.EaseElastic.extend(/** @lends cc.EaseElasticOut# */{ 621 /** 622 * @param {Number} time1 623 */ 624 update:function (time1) { 625 var newT = 0; 626 if (time1 == 0 || time1 == 1) { 627 newT = time1; 628 } else { 629 var s = this._period / 4; 630 newT = Math.pow(2, -10 * time1) * Math.sin((time1 - s) * Math.PI * 2 / this._period) + 1; 631 } 632 633 this._other.update(newT); 634 }, 635 636 /** 637 * @return {cc.ActionInterval} 638 */ 639 reverse:function () { 640 return cc.EaseElasticIn.create(this._other.reverse(), this._period); 641 } 642 }); 643 644 645 /** Creates the action with the inner action and the period in radians (default is 0.3) 646 * @param {cc.ActionInterval} action 647 * @param {Number} period 648 * @return {cc.EaseElasticOut} 649 * @example 650 * // example 651 * var moveEaseElasticOut = cc.EaseElasticOut.create(action, 3.0); 652 */ 653 cc.EaseElasticOut.create = function (action, period) { 654 var ret = new cc.EaseElasticOut(); 655 if (ret) { 656 if (period == null) { 657 ret.initWithAction(action); 658 } else { 659 ret.initWithAction(action, period); 660 } 661 } 662 return ret; 663 }; 664 665 /** 666 * Ease Elastic InOut action. 667 * @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. 668 * @class 669 * @extends cc.EaseElastic 670 */ 671 cc.EaseElasticInOut = cc.EaseElastic.extend(/** @lends cc.EaseElasticInOut# */{ 672 /** 673 * @param {Number} time1 674 */ 675 update:function (time1) { 676 var newT = 0; 677 if (time1 == 0 || time1 == 1) { 678 newT = time1; 679 } else { 680 time1 = time1 * 2; 681 if (!this._period) { 682 this._period = 0.3 * 1.5; 683 } 684 685 var s = this._period / 4; 686 687 time1 = time1 - 1; 688 if (time1 < 0) { 689 newT = -0.5 * Math.pow(2, 10 * time1) * Math.sin((time1 - s) * Math.PI * 2 / this._period); 690 } else { 691 newT = Math.pow(2, -10 * time1) * Math.sin((time1 - s) * Math.PI * 2 / this._period) * 0.5 + 1; 692 } 693 } 694 695 this._other.update(newT); 696 }, 697 698 /** 699 * @return {cc.ActionInterval} 700 */ 701 reverse:function () { 702 return cc.EaseInOut.create(this._other.reverse(), this._period); 703 } 704 }); 705 706 /** Creates the action with the inner action and the period in radians (default is 0.3) 707 * @param {cc.ActionInterval} action 708 * @param {Number} period 709 * @return {cc.EaseElasticInOut} 710 * @example 711 * // example 712 * var moveEaseElasticInOut = cc.EaseElasticInOut.create(action, 3.0); 713 */ 714 cc.EaseElasticInOut.create = function (action, period) { 715 var ret = new cc.EaseElasticInOut(); 716 if (ret) { 717 if (period == null) { 718 ret.initWithAction(action); 719 } else { 720 ret.initWithAction(action, period); 721 } 722 } 723 return ret; 724 }; 725 726 /** 727 * cc.EaseBounce abstract class. 728 * @class 729 * @extends cc.ActionEase 730 */ 731 cc.EaseBounce = cc.ActionEase.extend(/** @lends cc.EaseBounce# */{ 732 /** 733 * @param {Number} time1 734 * @return {Number} 735 */ 736 bounceTime:function (time1) { 737 if (time1 < 1 / 2.75) { 738 return 7.5625 * time1 * time1; 739 } else if (time1 < 2 / 2.75) { 740 time1 -= 1.5 / 2.75; 741 return 7.5625 * time1 * time1 + 0.75; 742 } else if (time1 < 2.5 / 2.75) { 743 time1 -= 2.25 / 2.75; 744 return 7.5625 * time1 * time1 + 0.9375; 745 } 746 747 time1 -= 2.625 / 2.75; 748 return 7.5625 * time1 * time1 + 0.984375; 749 }, 750 751 /** 752 * @return {cc.ActionInterval} 753 */ 754 reverse:function () { 755 return cc.EaseBounce.create(this._other.reverse()); 756 } 757 }); 758 759 /** creates the action 760 * @param {cc.ActionInterval} action 761 * @return {cc.EaseBounce} 762 * @example 763 * // example 764 * var moveEaseBounce = cc.EaseBounce.create(action); 765 */ 766 cc.EaseBounce.create = function (action) { 767 var ret = new cc.EaseBounce(); 768 if (ret) { 769 ret.initWithAction(action); 770 } 771 return ret; 772 }; 773 774 /** 775 * cc.EaseBounceIn action. 776 * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. 777 * @class 778 * @extends cc.EaseBounce 779 */ 780 cc.EaseBounceIn = cc.EaseBounce.extend(/** @lends cc.EaseBounceIn# */{ 781 /** 782 * @param {Number} time1 783 */ 784 update:function (time1) { 785 var newT = 1 - this.bounceTime(1 - time1); 786 this._other.update(newT); 787 }, 788 789 /** 790 * @return {cc.ActionInterval} 791 */ 792 reverse:function () { 793 return cc.EaseBounceOut.create(this._other.reverse()); 794 } 795 }); 796 797 /** creates the action 798 * @param {cc.ActionInterval} action 799 * @return {cc.EaseBounceIn} 800 * @example 801 * // example 802 * var moveEaseBounceIn = cc.EaseBounceIn.create(action); 803 */ 804 cc.EaseBounceIn.create = function (action) { 805 var ret = new cc.EaseBounceIn(); 806 if (ret) { 807 ret.initWithAction(action); 808 } 809 return ret; 810 }; 811 /** 812 * cc.EaseBounceOut action. 813 * @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. 814 * @class 815 * @extends cc.EaseBounce 816 */ 817 cc.EaseBounceOut = cc.EaseBounce.extend(/** @lends cc.EaseBounceOut# */{ 818 819 /** 820 * @param {Number} time1 821 */ 822 update:function (time1) { 823 var newT = this.bounceTime(time1); 824 this._other.update(newT); 825 }, 826 827 /** 828 * @return {cc.ActionInterval} 829 */ 830 reverse:function () { 831 return cc.EaseBounceIn.create(this._other.reverse()); 832 } 833 }); 834 835 /** creates the action 836 * @param {cc.ActionInterval} action 837 * @return {cc.EaseBounceOut} 838 * @example 839 * // example 840 * var moveEaseBounceOut = cc.EaseBounceOut.create(action); 841 */ 842 cc.EaseBounceOut.create = function (action) { 843 var ret = new cc.EaseBounceOut(); 844 if (ret) { 845 ret.initWithAction(action); 846 } 847 return ret; 848 }; 849 850 /** 851 * cc.EaseBounceInOut action. 852 * @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. 853 * @class 854 * @extends cc.EaseBounce 855 */ 856 cc.EaseBounceInOut = cc.EaseBounce.extend(/** @lends cc.EaseBounceInOut# */{ 857 858 /** 859 * @param {Number} time1 860 */ 861 update:function (time1) { 862 var newT = 0; 863 if (time1 < 0.5) { 864 time1 = time1 * 2; 865 newT = (1 - this.bounceTime(1 - time1)) * 0.5; 866 } else { 867 newT = this.bounceTime(time1 * 2 - 1) * 0.5 + 0.5; 868 } 869 870 this._other.update(newT); 871 }, 872 873 874 /** 875 * @return {cc.ActionInterval} 876 */ 877 reverse:function () { 878 return cc.EaseBounceInOut.create(this._other.reverse()); 879 } 880 }); 881 882 /** creates the action 883 * @param {cc.ActionInterval} action 884 * @return {cc.EaseBounceInOut} 885 * @example 886 * // example 887 * var moveEaseBounceInOut = cc.EaseBounceInOut.create(action); 888 */ 889 cc.EaseBounceInOut.create = function (action) { 890 var ret = new cc.EaseBounceInOut(); 891 if (ret) { 892 ret.initWithAction(action); 893 } 894 return ret; 895 }; 896 897 /** 898 * cc.EaseBackIn action. 899 * @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. 900 * @class 901 * @extends cc.ActionEase 902 */ 903 cc.EaseBackIn = cc.ActionEase.extend(/** @lends cc.EaseBackIn# */{ 904 905 /** 906 * @param {Number} time1 907 */ 908 update:function (time1) { 909 var overshoot = 1.70158; 910 this._other.update(time1 * time1 * ((overshoot + 1) * time1 - overshoot)); 911 912 }, 913 914 /** 915 * @return {cc.ActionInterval} 916 */ 917 reverse:function () { 918 return cc.EaseBackOut.create(this._other.reverse()); 919 920 } 921 }); 922 923 924 /** creates the action 925 * @param {cc.ActionInterval} action 926 * @return {cc.EaseBackIn} 927 * @example 928 * // example 929 * var moveEaseBackIn = cc.EaseBackIn.create(action); 930 */ 931 cc.EaseBackIn.create = function (action) { 932 var ret = new cc.EaseBackIn(); 933 if (ret) { 934 ret.initWithAction(action); 935 } 936 return ret; 937 }; 938 939 /** 940 * cc.EaseBackOut action. 941 * @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. 942 * @class 943 * @extends cc.ActionEase 944 */ 945 cc.EaseBackOut = cc.ActionEase.extend(/** @lends cc.EaseBackOut# */{ 946 /** 947 * @param {Number} time1 948 */ 949 update:function (time1) { 950 var overshoot = 1.70158; 951 952 time1 = time1 - 1; 953 this._other.update(time1 * time1 * ((overshoot + 1) * time1 + overshoot) + 1); 954 }, 955 956 /** 957 * @return {cc.ActionInterval} 958 */ 959 reverse:function () { 960 return cc.EaseBackIn.create(this._other.reverse()); 961 } 962 }); 963 964 /** creates the action 965 * @param {cc.ActionInterval} action 966 * @return {cc.EaseBackOut} 967 * @example 968 * // example 969 * var moveEaseBackOut = cc.EaseBackOut.create(action); 970 */ 971 cc.EaseBackOut.create = function (action) { 972 var ret = new cc.EaseBackOut(); 973 if (ret) { 974 ret.initWithAction(action); 975 } 976 return ret; 977 }; 978 979 /** 980 * cc.EaseBackInOut action. 981 * @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. 982 * @class 983 * @extends cc.ActionEase 984 */ 985 cc.EaseBackInOut = cc.ActionEase.extend(/** @lends cc.EaseBackInOut# */{ 986 /** 987 * @param {Number} time1 988 */ 989 update:function (time1) { 990 var overshoot = 1.70158 * 1.525; 991 992 time1 = time1 * 2; 993 if (time1 < 1) { 994 this._other.update((time1 * time1 * ((overshoot + 1) * time1 - overshoot)) / 2); 995 } else { 996 time1 = time1 - 2; 997 this._other.update((time1 * time1 * ((overshoot + 1) * time1 + overshoot)) / 2 + 1); 998 } 999 }, 1000 1001 /** 1002 * @return {cc.ActionInterval} 1003 */ 1004 reverse:function () { 1005 return cc.EaseBackInOut.create(this._other.reverse()); 1006 } 1007 }); 1008 1009 1010 /** creates the action 1011 * @param {cc.ActionInterval} action 1012 * @return {cc.EaseBackInOut} 1013 * @example 1014 * // example 1015 * var moveEaseBackInOut = cc.EaseBackInOut.create(action); 1016 */ 1017 cc.EaseBackInOut.create = function (action) { 1018 var ret = new cc.EaseBackInOut(); 1019 if (ret) { 1020 ret.initWithAction(action); 1021 } 1022 return ret; 1023 }; 1024 1025