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