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 cc.Assert(action != null, ""); 47 48 if (this.initWithDuration(action.getDuration())) { 49 this._inner = action; 50 return true; 51 } 52 return false; 53 }, 54 55 clone:function(){ 56 var action = new cc.ActionEase(); 57 action.initWithAction(this._inner.clone()); 58 return action; 59 }, 60 61 /** 62 * @param {cc.Node} target 63 */ 64 startWithTarget:function (target) { 65 cc.ActionInterval.prototype.startWithTarget.call(this, target); 66 this._inner.startWithTarget(this._target); 67 }, 68 69 /** 70 * Stop the action. 71 */ 72 stop:function () { 73 this._inner.stop(); 74 cc.ActionInterval.prototype.stop.call(this); 75 }, 76 77 /** 78 * @param {Number} time1 79 */ 80 update:function (time1) { 81 this._inner.update(time1); 82 }, 83 84 /** 85 * @return {cc.ActionInterval} 86 */ 87 reverse:function () { 88 return cc.ActionEase.create(this._inner.reverse()); 89 }, 90 91 getInnerAction:function(){ 92 return this._inner; 93 } 94 }); 95 96 /** creates the action of ActionEase 97 * @param {cc.ActionInterval} action 98 * @return {cc.ActionEase} 99 * @example 100 * // example 101 * var moveEase = cc.ActionEase.create(action); 102 */ 103 cc.ActionEase.create = function (action) { 104 var ret = new cc.ActionEase(); 105 if (ret) 106 ret.initWithAction(action); 107 return ret; 108 }; 109 110 /** 111 * Base class for Easing actions with rate parameters 112 * @class 113 * @extends cc.ActionEase 114 */ 115 cc.EaseRateAction = cc.ActionEase.extend(/** @lends cc.EaseRateAction# */{ 116 _rate:0, 117 ctor:function(){ 118 cc.ActionEase.prototype.ctor.call(this); 119 this._rate = 0; 120 }, 121 122 /** set rate value for the actions 123 * @param {Number} rate 124 */ 125 setRate:function (rate) { 126 this._rate = rate; 127 }, 128 129 /** get rate value for the actions 130 * @return {Number} 131 */ 132 getRate:function () { 133 return this._rate; 134 }, 135 136 /** 137 * Initializes the action with the inner action and the rate parameter 138 * @param {cc.ActionInterval} action 139 * @param {Number} rate 140 * @return {Boolean} 141 */ 142 initWithAction:function (action, rate) { 143 if (cc.ActionEase.prototype.initWithAction.call(this, action)) { 144 this._rate = rate; 145 return true; 146 } 147 return false; 148 }, 149 150 clone:function(){ 151 var action = new cc.EaseRateAction(); 152 action.initWithAction(this._inner.clone(), this._rate); 153 return action; 154 }, 155 156 /** 157 * @return {cc.ActionInterval} 158 */ 159 reverse:function () { 160 return cc.EaseRateAction.create(this._inner.reverse(), 1 / this._rate); 161 } 162 }); 163 164 /** Creates the action with the inner action and the rate parameter 165 * @param {cc.ActionInterval} action 166 * @param {Number} rate 167 * @return {cc.EaseRateAction} 168 * @example 169 * // example 170 * var moveEaseRateAction = cc.EaseRateAction.create(action, 3.0); 171 */ 172 cc.EaseRateAction.create = function (action, rate) { 173 var ret = new cc.EaseRateAction(); 174 if (ret) 175 ret.initWithAction(action, rate); 176 return ret; 177 }; 178 179 /** 180 * cc.EaseIn action with a rate 181 * @class 182 * @extends cc.EaseRateAction 183 */ 184 cc.EaseIn = cc.EaseRateAction.extend(/** @lends cc.EaseIn# */{ 185 /** 186 * @param {Number} time1 187 */ 188 update:function (time1) { 189 this._inner.update(Math.pow(time1, this._rate)); 190 }, 191 192 /** 193 * @return {cc.ActionInterval} 194 */ 195 reverse:function () { 196 return cc.EaseIn.create(this._inner.reverse(), 1 / this._rate); 197 }, 198 199 clone:function(){ 200 var action = new cc.EaseIn(); 201 action.initWithAction(this._inner.clone(), this._rate); 202 return action; 203 } 204 }); 205 206 /** Creates the action with the inner action and the rate parameter 207 * @param {cc.ActionInterval} action 208 * @param {Number} rate 209 * @return {cc.EaseIn} 210 * @example 211 * // example 212 * var moveEaseIn = cc.EaseIn.create(action, 3.0); 213 */ 214 cc.EaseIn.create = function (action, rate) { 215 var ret = new cc.EaseIn(); 216 if (ret) 217 ret.initWithAction(action, rate); 218 return ret; 219 }; 220 /** 221 * cc.EaseOut action with a rate 222 * @class 223 * @extends cc.EaseRateAction 224 */ 225 cc.EaseOut = cc.EaseRateAction.extend(/** @lends cc.EaseOut# */{ 226 /** 227 * @param {Number} time1 228 */ 229 update:function (time1) { 230 this._inner.update(Math.pow(time1, 1 / this._rate)); 231 }, 232 233 /** 234 * @return {cc.ActionInterval} 235 */ 236 reverse:function () { 237 return cc.EaseOut.create(this._inner.reverse(), 1 / this._rate); 238 }, 239 240 clone:function(){ 241 var action = new cc.EaseOut(); 242 action.initWithAction(this._inner.clone(),this._rate); 243 return action; 244 } 245 }); 246 247 /** Creates the action with the inner action and the rate parameter 248 * @param {cc.ActionInterval} action 249 * @param {Number} rate 250 * @return {cc.EaseOut} 251 * @example 252 * // example 253 * var moveEaseOut = cc.EaseOut.create(action, 3.0); 254 */ 255 cc.EaseOut.create = function (action, rate) { 256 var ret = new cc.EaseOut(); 257 if (ret) 258 ret.initWithAction(action, rate); 259 return ret; 260 }; 261 262 /** 263 * cc.EaseInOut action with a rate 264 * @class 265 * @extends cc.EaseRateAction 266 */ 267 cc.EaseInOut = cc.EaseRateAction.extend(/** @lends cc.EaseInOut# */{ 268 /** 269 * @param {Number} time1 270 */ 271 update:function (time1) { 272 time1 *= 2; 273 if (time1 < 1) 274 this._inner.update(0.5 * Math.pow(time1, this._rate)); 275 else 276 this._inner.update(1.0 - 0.5 * Math.pow(2 - time1, this._rate)); 277 }, 278 279 clone:function(){ 280 var action = new cc.EaseInOut(); 281 action.initWithAction(this._inner.clone(), this._rate); 282 return action; 283 }, 284 285 /** 286 * @return {cc.ActionInterval} 287 */ 288 reverse:function () { 289 return cc.EaseInOut.create(this._inner.reverse(), this._rate); 290 } 291 }); 292 293 /** Creates the action with the inner action and the rate parameter 294 * @param {cc.ActionInterval} action 295 * @param {Number} rate 296 * @return {cc.EaseInOut} 297 * @example 298 * // example 299 * var moveEaseInOut = cc.EaseInOut.create(action, 3.0); 300 */ 301 cc.EaseInOut.create = function (action, rate) { 302 var ret = new cc.EaseInOut(); 303 if (ret) 304 ret.initWithAction(action, rate); 305 return ret; 306 }; 307 /** 308 * cc.Ease Exponential In 309 * @class 310 * @extends cc.ActionEase 311 */ 312 cc.EaseExponentialIn = cc.ActionEase.extend(/** @lends cc.EaseExponentialIn# */{ 313 /** 314 * @param {Number} time1 315 */ 316 update:function (time1) { 317 this._inner.update(time1 === 0 ? 0 : Math.pow(2, 10 * (time1 - 1))); 318 }, 319 320 /** 321 * @return {cc.ActionInterval} 322 */ 323 reverse:function () { 324 return cc.EaseExponentialOut.create(this._inner.reverse()); 325 }, 326 327 clone:function(){ 328 var action = new cc.EaseExponentialIn(); 329 action.initWithAction(this._inner.clone()); 330 return action; 331 } 332 }); 333 334 /** creates the action 335 * @param {cc.ActionInterval} action 336 * @return {cc.EaseExponentialIn} 337 * @example 338 * // example 339 * var moveEaseExponentialIn = cc.EaseExponentialIn.create(action); 340 */ 341 cc.EaseExponentialIn.create = function (action) { 342 var ret = new cc.EaseExponentialIn(); 343 if (ret) 344 ret.initWithAction(action); 345 return ret; 346 }; 347 /** 348 * Ease Exponential Out 349 * @class 350 * @extends cc.ActionEase 351 */ 352 cc.EaseExponentialOut = cc.ActionEase.extend(/** @lends cc.EaseExponentialOut# */{ 353 354 /** 355 * @param {Number} time1 356 */ 357 update:function (time1) { 358 this._inner.update(time1 == 1 ? 1 : (-(Math.pow(2, -10 * time1)) + 1)); 359 }, 360 361 /** 362 * @return {cc.ActionInterval} 363 */ 364 reverse:function () { 365 return cc.EaseExponentialIn.create(this._inner.reverse()); 366 }, 367 368 clone:function(){ 369 var action = new cc.EaseExponentialOut(); 370 action.initWithAction(this._inner.clone()); 371 return action; 372 } 373 }); 374 375 /** creates the action 376 * @param {cc.ActionInterval} action 377 * @return {cc.EaseExponentialOut} 378 * @example 379 * // example 380 * var moveEaseExponentialOut = cc.EaseExponentialOut.create(action); 381 */ 382 cc.EaseExponentialOut.create = function (action) { 383 var ret = new cc.EaseExponentialOut(); 384 if (ret) 385 ret.initWithAction(action); 386 return ret; 387 }; 388 389 /** 390 * Ease Exponential InOut 391 * @class 392 * @extends cc.ActionEase 393 */ 394 cc.EaseExponentialInOut = cc.ActionEase.extend(/** @lends cc.EaseExponentialInOut# */{ 395 /** 396 * @param {Number} time 397 */ 398 update:function (time) { 399 if( time != 1 && time !== 0) { 400 time *= 2; 401 if (time < 1) 402 time = 0.5 * Math.pow(2, 10 * (time - 1)); 403 else 404 time = 0.5 * (-Math.pow(2, -10 * (time - 1)) + 2); 405 } 406 this._inner.update(time); 407 }, 408 409 /** 410 * @return {cc.EaseExponentialInOut} 411 */ 412 reverse:function () { 413 return cc.EaseExponentialInOut.create(this._inner.reverse()); 414 }, 415 416 clone:function(){ 417 var action = new cc.EaseExponentialInOut(); 418 action.initWithAction(this._inner.clone()); 419 return action; 420 } 421 }); 422 423 /** creates the action 424 * @param {cc.ActionInterval} action 425 * @return {cc.EaseExponentialInOut} 426 * @example 427 * // example 428 * var moveEaseExponentialInOut = cc.EaseExponentialInOut.create(action); 429 */ 430 cc.EaseExponentialInOut.create = function (action) { 431 var ret = new cc.EaseExponentialInOut(); 432 if (ret) 433 ret.initWithAction(action); 434 return ret; 435 }; 436 437 438 /** 439 * Ease Sine In 440 * @class 441 * @extends cc.ActionEase 442 */ 443 cc.EaseSineIn = cc.ActionEase.extend(/** @lends cc.EaseSineIn# */{ 444 /** 445 * @param {Number} time1 446 */ 447 update:function (time1) { 448 time1 = time1===0 || time1==1 ? time1 : -1 * Math.cos(time1 * Math.PI / 2) + 1; 449 this._inner.update(time1); 450 }, 451 452 /** 453 * @return {cc.ActionInterval} 454 */ 455 reverse:function () { 456 return cc.EaseSineOut.create(this._inner.reverse()); 457 }, 458 459 clone:function(){ 460 var action = new cc.EaseSineIn(); 461 action.initWithAction(this._inner.clone()); 462 return action; 463 } 464 }); 465 466 /** creates the action 467 * @param {cc.ActionInterval} action 468 * @return {cc.EaseSineIn} 469 * @example 470 * // example 471 * var moveSineIn = cc.EaseSineIn.create(action); 472 */ 473 cc.EaseSineIn.create = function (action) { 474 var ret = new cc.EaseSineIn(); 475 if (ret) 476 ret.initWithAction(action); 477 return ret; 478 }; 479 /** 480 * Ease Sine Out 481 * @class 482 * @extends cc.ActionEase 483 */ 484 cc.EaseSineOut = cc.ActionEase.extend(/** @lends cc.EaseSineOut# */{ 485 /** 486 * @param {Number} time1 487 */ 488 update:function (time1) { 489 time1 = time1===0 || time1==1 ? time1 : Math.sin(time1 * Math.PI / 2); 490 this._inner.update(time1); 491 }, 492 493 /** 494 * @return {cc.ActionInterval} 495 */ 496 reverse:function () { 497 return cc.EaseSineIn.create(this._inner.reverse()); 498 }, 499 500 clone:function(){ 501 var action = new cc.EaseSineOut(); 502 action.initWithAction(this._inner.clone()); 503 return action; 504 } 505 }); 506 507 508 /** creates the action 509 * @param {cc.ActionInterval} action 510 * @return {cc.EaseSineOut} 511 * @example 512 * // example 513 * var moveEaseOut = cc.EaseSineOut.create(action); 514 */ 515 cc.EaseSineOut.create = function (action) { 516 var ret = new cc.EaseSineOut(); 517 if (ret) 518 ret.initWithAction(action); 519 return ret; 520 }; 521 522 523 /** 524 * Ease Sine InOut 525 * @class 526 * @extends cc.ActionEase 527 */ 528 cc.EaseSineInOut = cc.ActionEase.extend(/** @lends cc.EaseSineInOut# */{ 529 /** 530 * @param {Number} time1 531 */ 532 update:function (time1) { 533 time1 = time1===0 || time1==1 ? time1 : -0.5 * (Math.cos(Math.PI * time1) - 1); 534 this._inner.update(time1); 535 536 }, 537 538 clone:function(){ 539 var action = new cc.EaseSineInOut(); 540 action.initWithAction(this._inner.clone()); 541 return action; 542 }, 543 544 /** 545 * @return {cc.ActionInterval} 546 */ 547 reverse:function () { 548 return cc.EaseSineInOut.create(this._inner.reverse()); 549 } 550 }); 551 552 /** creates the action 553 * @param {cc.ActionInterval} action 554 * @return {cc.EaseSineInOut} 555 * @example 556 * // example 557 * var moveEaseSineInOut = cc.EaseSineInOut.create(action); 558 */ 559 cc.EaseSineInOut.create = function (action) { 560 var ret = new cc.EaseSineInOut(); 561 if (ret) 562 ret.initWithAction(action); 563 return ret; 564 }; 565 566 /** 567 * Ease Elastic abstract class 568 * @class 569 * @extends cc.ActionEase 570 */ 571 cc.EaseElastic = cc.ActionEase.extend(/** @lends cc.EaseElastic# */{ 572 _period:null, 573 ctor:function(){ 574 cc.ActionEase.prototype.ctor.call(this); 575 this._period = 0.3; 576 }, 577 578 /** get period of the wave in radians. default is 0.3 579 * @return {Number} 580 */ 581 getPeriod:function () { 582 return this._period; 583 }, 584 585 /** set period of the wave in radians. 586 * @param {Number} period 587 */ 588 setPeriod:function (period) { 589 this._period = period; 590 }, 591 592 /** Initializes the action with the inner action and the period in radians (default is 0.3) 593 * @param {cc.ActionInterval} action 594 * @param {Number} [period=0.3] 595 * @return {Boolean} 596 */ 597 initWithAction:function (action, period) { 598 cc.ActionEase.prototype.initWithAction.call(this, action); 599 this._period = (period == null) ? 0.3 : period; 600 return true; 601 }, 602 603 /** 604 * @return {Null} 605 */ 606 reverse:function () { 607 cc.Assert(0, "Override me"); 608 return null; 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