1 /**************************************************************************** 2 Copyright (c) 2008-2010 Ricardo Quesada 3 Copyright (c) 2011-2012 cocos2d-x.org 4 Copyright (c) 2013-2014 Chukong Technologies 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 /** 37 * creates the action of ActionEase 38 * 39 * Constructor of cc.ActionEase 40 * @param {cc.ActionInterval} action 41 * 42 * @example 43 * var moveEase = new cc.ActionEase(action); 44 */ 45 ctor: function (action) { 46 cc.ActionInterval.prototype.ctor.call(this); 47 action && this.initWithAction(action); 48 }, 49 50 /** initializes the action 51 * @param {cc.ActionInterval} action 52 * @return {Boolean} 53 */ 54 initWithAction:function (action) { 55 if(!action) 56 throw "cc.ActionEase.initWithAction(): action must be non nil"; 57 58 if (this.initWithDuration(action.getDuration())) { 59 this._inner = action; 60 return true; 61 } 62 return false; 63 }, 64 65 clone:function(){ 66 var action = new cc.ActionEase(); 67 action.initWithAction(this._inner.clone()); 68 return action; 69 }, 70 71 /** 72 * @param {cc.Node} target 73 */ 74 startWithTarget:function (target) { 75 cc.ActionInterval.prototype.startWithTarget.call(this, target); 76 this._inner.startWithTarget(this.target); 77 }, 78 79 /** 80 * Stop the action. 81 */ 82 stop:function () { 83 this._inner.stop(); 84 cc.ActionInterval.prototype.stop.call(this); 85 }, 86 87 /** 88 * @param {Number} time1 89 */ 90 update:function (time1) { 91 this._inner.update(time1); 92 }, 93 94 /** 95 * @return {cc.ActionInterval} 96 */ 97 reverse:function () { 98 return cc.ActionEase.create(this._inner.reverse()); 99 }, 100 101 getInnerAction:function(){ 102 return this._inner; 103 } 104 }); 105 106 /** creates the action of ActionEase 107 * @param {cc.ActionInterval} action 108 * @return {cc.ActionEase} 109 * @example 110 * // example 111 * var moveEase = cc.ActionEase.create(action); 112 */ 113 cc.ActionEase.create = function (action) { 114 return new cc.ActionEase(action); 115 }; 116 117 /** 118 * Base class for Easing actions with rate parameters 119 * @class 120 * @extends cc.ActionEase 121 */ 122 cc.EaseRateAction = cc.ActionEase.extend(/** @lends cc.EaseRateAction# */{ 123 _rate:0, 124 125 /** 126 * Creates the action with the inner action and the rate parameter 127 * 128 * Constructor of cc.EaseRateAction 129 * @param {cc.ActionInterval} action 130 * @param {Number} rate 131 * 132 * @example 133 * // example 134 * var moveEaseRateAction = new cc.EaseRateAction(action, 3.0); 135 */ 136 ctor: function(action, rate){ 137 cc.ActionEase.prototype.ctor.call(this); 138 139 rate !== undefined && this.initWithAction(action, rate); 140 }, 141 142 /** set rate value for the actions 143 * @param {Number} rate 144 */ 145 setRate:function (rate) { 146 this._rate = rate; 147 }, 148 149 /** get rate value for the actions 150 * @return {Number} 151 */ 152 getRate:function () { 153 return this._rate; 154 }, 155 156 /** 157 * Initializes the action with the inner action and the rate parameter 158 * @param {cc.ActionInterval} action 159 * @param {Number} rate 160 * @return {Boolean} 161 */ 162 initWithAction:function (action, rate) { 163 if (cc.ActionEase.prototype.initWithAction.call(this, action)) { 164 this._rate = rate; 165 return true; 166 } 167 return false; 168 }, 169 170 clone:function(){ 171 var action = new cc.EaseRateAction(); 172 action.initWithAction(this._inner.clone(), this._rate); 173 return action; 174 }, 175 176 /** 177 * @return {cc.EaseRateAction} 178 */ 179 reverse:function () { 180 return cc.EaseRateAction.create(this._inner.reverse(), 1 / this._rate); 181 } 182 }); 183 184 /** Creates the action with the inner action and the rate parameter 185 * @param {cc.ActionInterval} action 186 * @param {Number} rate 187 * @return {cc.EaseRateAction} 188 * @example 189 * // example 190 * var moveEaseRateAction = cc.EaseRateAction.create(action, 3.0); 191 */ 192 cc.EaseRateAction.create = function (action, rate) { 193 return new cc.EaseRateAction(action, rate); 194 }; 195 196 /** 197 * cc.EaseIn action with a rate 198 * @class 199 * @extends cc.EaseRateAction 200 */ 201 cc.EaseIn = cc.EaseRateAction.extend(/** @lends cc.EaseIn# */{ 202 /** 203 * @param {Number} time1 204 */ 205 update:function (time1) { 206 this._inner.update(Math.pow(time1, this._rate)); 207 }, 208 209 /** 210 * @return {cc.EaseIn} 211 */ 212 reverse:function () { 213 return cc.EaseIn.create(this._inner.reverse(), 1 / this._rate); 214 }, 215 216 clone:function(){ 217 var action = new cc.EaseIn(); 218 action.initWithAction(this._inner.clone(), this._rate); 219 return action; 220 } 221 }); 222 223 /** Creates the action with the inner action and the rate parameter 224 * @param {cc.ActionInterval} action 225 * @param {Number} rate 226 * @return {cc.EaseIn} 227 * @example 228 * // example 229 * var moveEaseIn = cc.EaseIn.create(action, 3.0); 230 */ 231 cc.EaseIn.create = function (action, rate) { 232 return new cc.EaseIn(action, rate); 233 }; 234 235 cc.easeIn = function (rate) { 236 return { 237 _rate: rate, 238 easing: function (dt) { 239 return Math.pow(dt, this._rate); 240 }, 241 reverse: function(){ 242 return cc.easeIn(1 / this._rate); 243 } 244 }; 245 }; 246 247 /** 248 * cc.EaseOut action with a rate 249 * @class 250 * @extends cc.EaseRateAction 251 */ 252 cc.EaseOut = cc.EaseRateAction.extend(/** @lends cc.EaseOut# */{ 253 /** 254 * @param {Number} time1 255 */ 256 update:function (time1) { 257 this._inner.update(Math.pow(time1, 1 / this._rate)); 258 }, 259 260 /** 261 * @return {cc.EaseOut} 262 */ 263 reverse:function () { 264 return cc.EaseOut.create(this._inner.reverse(), 1 / this._rate); 265 }, 266 267 clone:function(){ 268 var action = new cc.EaseOut(); 269 action.initWithAction(this._inner.clone(),this._rate); 270 return action; 271 } 272 }); 273 274 /** Creates the action with the inner action and the rate parameter 275 * @param {cc.ActionInterval} action 276 * @param {Number} rate 277 * @return {cc.EaseOut} 278 * @example 279 * // example 280 * var moveEaseOut = cc.EaseOut.create(action, 3.0); 281 */ 282 cc.EaseOut.create = function (action, rate) { 283 return new cc.EaseOut(action, rate); 284 }; 285 286 cc.easeOut = function (rate) { 287 return { 288 _rate: rate, 289 easing: function (dt) { 290 return Math.pow(dt, 1 / this._rate); 291 }, 292 reverse: function(){ 293 return cc.easeOut(1 / this._rate) 294 } 295 }; 296 }; 297 298 /** 299 * cc.EaseInOut action with a rate 300 * @class 301 * @extends cc.EaseRateAction 302 */ 303 cc.EaseInOut = cc.EaseRateAction.extend(/** @lends cc.EaseInOut# */{ 304 /** 305 * @param {Number} time1 306 */ 307 update:function (time1) { 308 time1 *= 2; 309 if (time1 < 1) 310 this._inner.update(0.5 * Math.pow(time1, this._rate)); 311 else 312 this._inner.update(1.0 - 0.5 * Math.pow(2 - time1, this._rate)); 313 }, 314 315 clone:function(){ 316 var action = new cc.EaseInOut(); 317 action.initWithAction(this._inner.clone(), this._rate); 318 return action; 319 }, 320 321 /** 322 * @return {cc.EaseInOut} 323 */ 324 reverse:function () { 325 return cc.EaseInOut.create(this._inner.reverse(), this._rate); 326 } 327 }); 328 329 /** Creates the action with the inner action and the rate parameter 330 * @param {cc.ActionInterval} action 331 * @param {Number} rate 332 * @return {cc.EaseInOut} 333 * @example 334 * // example 335 * var moveEaseInOut = cc.EaseInOut.create(action, 3.0); 336 */ 337 cc.EaseInOut.create = function (action, rate) { 338 return new cc.EaseInOut(action, rate); 339 }; 340 341 cc.easeInOut = function (rate) { 342 return { 343 _rate: rate, 344 easing: function (dt) { 345 dt *= 2; 346 if (dt < 1) 347 return 0.5 * Math.pow(dt, this._rate); 348 else 349 return 1.0 - 0.5 * Math.pow(2 - dt, this._rate); 350 }, 351 reverse: function(){ 352 return cc.easeInOut(this._rate); 353 } 354 }; 355 }; 356 357 /** 358 * cc.Ease Exponential In 359 * @class 360 * @extends cc.ActionEase 361 */ 362 cc.EaseExponentialIn = cc.ActionEase.extend(/** @lends cc.EaseExponentialIn# */{ 363 /** 364 * @param {Number} time1 365 */ 366 update:function (time1) { 367 this._inner.update(time1 === 0 ? 0 : Math.pow(2, 10 * (time1 - 1))); 368 }, 369 370 /** 371 * @return {cc.EaseExponentialOut} 372 */ 373 reverse:function () { 374 return cc.EaseExponentialOut.create(this._inner.reverse()); 375 }, 376 377 clone:function(){ 378 var action = new cc.EaseExponentialIn(); 379 action.initWithAction(this._inner.clone()); 380 return action; 381 } 382 }); 383 384 /** creates the action 385 * @param {cc.ActionInterval} action 386 * @return {cc.EaseExponentialIn} 387 * @example 388 * // example 389 * var moveEaseExponentialIn = cc.EaseExponentialIn.create(action); 390 */ 391 cc.EaseExponentialIn.create = function (action) { 392 return new cc.EaseExponentialIn(action); 393 }; 394 395 cc._easeExponentialInObj = { 396 easing: function(dt){ 397 return dt === 0 ? 0 : Math.pow(2, 10 * (dt - 1)); 398 }, 399 reverse: function(){ 400 return cc._easeExponentialOutObj; 401 } 402 }; 403 cc.easeExponentialIn = function(){ 404 return cc._easeExponentialInObj; 405 }; 406 407 /** 408 * Ease Exponential Out 409 * @class 410 * @extends cc.ActionEase 411 */ 412 cc.EaseExponentialOut = cc.ActionEase.extend(/** @lends cc.EaseExponentialOut# */{ 413 /** 414 * @param {Number} time1 415 */ 416 update:function (time1) { 417 this._inner.update(time1 == 1 ? 1 : (-(Math.pow(2, -10 * time1)) + 1)); 418 }, 419 420 /** 421 * @return {cc.EaseExponentialIn} 422 */ 423 reverse:function () { 424 return cc.EaseExponentialIn.create(this._inner.reverse()); 425 }, 426 427 clone:function(){ 428 var action = new cc.EaseExponentialOut(); 429 action.initWithAction(this._inner.clone()); 430 return action; 431 } 432 }); 433 434 /** creates the action 435 * @param {cc.ActionInterval} action 436 * @return {cc.EaseExponentialOut} 437 * @example 438 * // example 439 * var moveEaseExponentialOut = cc.EaseExponentialOut.create(action); 440 */ 441 cc.EaseExponentialOut.create = function (action) { 442 return new cc.EaseExponentialOut(action); 443 }; 444 445 cc._easeExponentialOutObj = { 446 easing: function(dt){ 447 return dt == 1 ? 1 : (-(Math.pow(2, -10 * dt)) + 1); 448 }, 449 reverse: function(){ 450 return cc._easeExponentialInObj; 451 } 452 }; 453 cc.easeExponentialOut = function(){ 454 return cc._easeExponentialOutObj; 455 }; 456 457 /** 458 * Ease Exponential InOut 459 * @class 460 * @extends cc.ActionEase 461 */ 462 cc.EaseExponentialInOut = cc.ActionEase.extend(/** @lends cc.EaseExponentialInOut# */{ 463 /** 464 * @param {Number} time 465 */ 466 update:function (time) { 467 if( time != 1 && time !== 0) { 468 time *= 2; 469 if (time < 1) 470 time = 0.5 * Math.pow(2, 10 * (time - 1)); 471 else 472 time = 0.5 * (-Math.pow(2, -10 * (time - 1)) + 2); 473 } 474 this._inner.update(time); 475 }, 476 477 /** 478 * @return {cc.EaseExponentialInOut} 479 */ 480 reverse:function () { 481 return cc.EaseExponentialInOut.create(this._inner.reverse()); 482 }, 483 484 clone:function(){ 485 var action = new cc.EaseExponentialInOut(); 486 action.initWithAction(this._inner.clone()); 487 return action; 488 } 489 }); 490 491 /** creates an EaseExponentialInOut action 492 * @param {cc.ActionInterval} action 493 * @return {cc.EaseExponentialInOut} 494 * @example 495 * // example 496 * var moveEaseExponentialInOut = cc.EaseExponentialInOut.create(action); 497 */ 498 cc.EaseExponentialInOut.create = function (action) { 499 return new cc.EaseExponentialInOut(action); 500 }; 501 502 cc._easeExponentialInOutObj = { 503 easing: function(dt){ 504 if( dt !== 1 && dt !== 0) { 505 dt *= 2; 506 if (dt < 1) 507 return 0.5 * Math.pow(2, 10 * (dt - 1)); 508 else 509 return 0.5 * (-Math.pow(2, -10 * (dt - 1)) + 2); 510 } 511 return dt; 512 }, 513 reverse: function(){ 514 return cc._easeExponentialInOutObj; 515 } 516 }; 517 cc.easeExponentialInOut = function(){ 518 return cc._easeExponentialInOutObj; 519 }; 520 521 /** 522 * Ease Sine In 523 * @class 524 * @extends cc.ActionEase 525 */ 526 cc.EaseSineIn = cc.ActionEase.extend(/** @lends cc.EaseSineIn# */{ 527 /** 528 * @param {Number} time1 529 */ 530 update:function (time1) { 531 time1 = time1===0 || time1===1 ? time1 : -1 * Math.cos(time1 * Math.PI / 2) + 1; 532 this._inner.update(time1); 533 }, 534 535 /** 536 * @return {cc.EaseSineOut} 537 */ 538 reverse:function () { 539 return cc.EaseSineOut.create(this._inner.reverse()); 540 }, 541 542 clone:function(){ 543 var action = new cc.EaseSineIn(); 544 action.initWithAction(this._inner.clone()); 545 return action; 546 } 547 }); 548 549 /** creates an EaseSineIn action 550 * @param {cc.ActionInterval} action 551 * @return {cc.EaseSineIn} 552 * @example 553 * // example 554 * var moveSineIn = cc.EaseSineIn.create(action); 555 */ 556 cc.EaseSineIn.create = function (action) { 557 return new cc.EaseSineIn(action); 558 }; 559 560 cc._easeSineInObj = { 561 easing: function(dt){ 562 return (dt===0 || dt===1) ? dt : -1 * Math.cos(dt * Math.PI / 2) + 1; 563 }, 564 reverse: function(){ 565 return cc._easeSineOutObj; 566 } 567 }; 568 cc.easeSineIn = function(){ 569 return cc._easeSineInObj; 570 }; 571 572 /** 573 * Ease Sine Out 574 * @class 575 * @extends cc.ActionEase 576 */ 577 cc.EaseSineOut = cc.ActionEase.extend(/** @lends cc.EaseSineOut# */{ 578 /** 579 * @param {Number} time1 580 */ 581 update:function (time1) { 582 time1 = time1===0 || time1===1 ? time1 : Math.sin(time1 * Math.PI / 2); 583 this._inner.update(time1); 584 }, 585 586 /** 587 * @return {cc.EaseSineIn} 588 */ 589 reverse:function () { 590 return cc.EaseSineIn.create(this._inner.reverse()); 591 }, 592 593 clone:function(){ 594 var action = new cc.EaseSineOut(); 595 action.initWithAction(this._inner.clone()); 596 return action; 597 } 598 }); 599 600 /** creates an EaseSineOut action 601 * @param {cc.ActionInterval} action 602 * @return {cc.EaseSineOut} 603 * @example 604 * // example 605 * var moveEaseOut = cc.EaseSineOut.create(action); 606 */ 607 cc.EaseSineOut.create = function (action) { 608 return new cc.EaseSineOut(action); 609 }; 610 611 cc._easeSineOutObj = { 612 easing: function(dt){ 613 return (dt===0 || dt==1) ? dt : Math.sin(dt * Math.PI / 2); 614 }, 615 reverse: function(){ 616 return cc._easeSineInObj; 617 } 618 }; 619 cc.easeSineOut = function(){ 620 return cc._easeSineOutObj; 621 }; 622 623 /** 624 * Ease Sine InOut 625 * @class 626 * @extends cc.ActionEase 627 */ 628 cc.EaseSineInOut = cc.ActionEase.extend(/** @lends cc.EaseSineInOut# */{ 629 /** 630 * @param {Number} time1 631 */ 632 update:function (time1) { 633 time1 = time1===0 || time1===1 ? time1 : -0.5 * (Math.cos(Math.PI * time1) - 1); 634 this._inner.update(time1); 635 }, 636 637 clone:function(){ 638 var action = new cc.EaseSineInOut(); 639 action.initWithAction(this._inner.clone()); 640 return action; 641 }, 642 643 /** 644 * @return {cc.EaseSineInOut} 645 */ 646 reverse:function () { 647 return cc.EaseSineInOut.create(this._inner.reverse()); 648 } 649 }); 650 651 /** creates the action 652 * @param {cc.ActionInterval} action 653 * @return {cc.EaseSineInOut} 654 * @example 655 * // example 656 * var moveEaseSineInOut = cc.EaseSineInOut.create(action); 657 */ 658 cc.EaseSineInOut.create = function (action) { 659 return new cc.EaseSineInOut(action); 660 }; 661 662 cc._easeSineInOutObj = { 663 easing: function(dt){ 664 return (dt === 0 || dt === 1) ? dt : -0.5 * (Math.cos(Math.PI * dt) - 1); 665 }, 666 reverse: function(){ 667 return cc._easeSineInOutObj; 668 } 669 }; 670 cc.easeSineInOut = function(){ 671 return cc._easeSineInOutObj; 672 }; 673 674 /** 675 * Ease Elastic abstract class 676 * @class 677 * @extends cc.ActionEase 678 */ 679 cc.EaseElastic = cc.ActionEase.extend(/** @lends cc.EaseElastic# */{ 680 _period: 0.3, 681 682 /** Creates the action with the inner action and the period in radians (default is 0.3) 683 * 684 * Constructor of cc.EaseElastic 685 * @param {cc.ActionInterval} action 686 * @param {Number} [period=0.3] 687 * 688 * @example 689 * // example 690 * var moveEaseElastic = new cc.EaseElastic(action, 3.0); 691 */ 692 ctor:function(action, period){ 693 cc.ActionEase.prototype.ctor.call(this); 694 695 action && this.initWithAction(action, period); 696 }, 697 698 /** get period of the wave in radians. default is 0.3 699 * @return {Number} 700 */ 701 getPeriod:function () { 702 return this._period; 703 }, 704 705 /** set period of the wave in radians. 706 * @param {Number} period 707 */ 708 setPeriod:function (period) { 709 this._period = period; 710 }, 711 712 /** Initializes the action with the inner action and the period in radians (default is 0.3) 713 * @param {cc.ActionInterval} action 714 * @param {Number} [period=0.3] 715 * @return {Boolean} 716 */ 717 initWithAction:function (action, period) { 718 cc.ActionEase.prototype.initWithAction.call(this, action); 719 this._period = (period == null) ? 0.3 : period; 720 return true; 721 }, 722 723 /** 724 * @return {Null} 725 */ 726 reverse:function () { 727 cc.log("cc.EaseElastic.reverse(): it should be overridden in subclass."); 728 return null; 729 }, 730 731 clone:function(){ 732 var action = new cc.EaseElastic(); 733 action.initWithAction(this._inner.clone(), this._period); 734 return action; 735 } 736 }); 737 738 /** Creates the action with the inner action and the period in radians (default is 0.3) 739 * @param {cc.ActionInterval} action 740 * @param {Number} [period=0.3] 741 * @return {cc.EaseElastic} 742 * @example 743 * // example 744 * var moveEaseElastic = cc.EaseElastic.create(action, 3.0); 745 */ 746 cc.EaseElastic.create = function (action, period) { 747 return new cc.EaseElastic(action, period); 748 }; 749 750 /** 751 * Ease Elastic In action. 752 * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. 753 * @class 754 * @extends cc.EaseElastic 755 */ 756 cc.EaseElasticIn = cc.EaseElastic.extend(/** @lends cc.EaseElasticIn# */{ 757 /** 758 * @param {Number} time1 759 */ 760 update:function (time1) { 761 var newT = 0; 762 if (time1 === 0 || time1 === 1) { 763 newT = time1; 764 } else { 765 var s = this._period / 4; 766 time1 = time1 - 1; 767 newT = -Math.pow(2, 10 * time1) * Math.sin((time1 - s) * Math.PI * 2 / this._period); 768 } 769 this._inner.update(newT); 770 }, 771 772 /** 773 * @return {cc.EaseElasticOut} 774 */ 775 reverse:function () { 776 return cc.EaseElasticOut.create(this._inner.reverse(), this._period); 777 }, 778 779 clone:function(){ 780 var action = new cc.EaseElasticIn(); 781 action.initWithAction(this._inner.clone(), this._period); 782 return action; 783 } 784 }); 785 786 /** Creates the action with the inner action and the period in radians (default is 0.3) 787 * @param {cc.ActionInterval} action 788 * @param {Number} [period=0.3] 789 * @return {cc.EaseElasticIn} 790 * @example 791 * // example 792 * var moveEaseElasticIn = cc.EaseElasticIn.create(action, 3.0); 793 */ 794 cc.EaseElasticIn.create = function (action, period) { 795 return new cc.EaseElasticIn(action, period); 796 }; 797 798 //default ease elastic in object (period = 0.3) 799 cc._easeElasticInObj = { 800 easing:function(dt){ 801 if (dt === 0 || dt === 1) 802 return dt; 803 dt = dt - 1; 804 return -Math.pow(2, 10 * dt) * Math.sin((dt - (0.3 / 4)) * Math.PI * 2 / 0.3); 805 }, 806 reverse:function(){ 807 return cc._easeElasticOutObj; 808 } 809 }; 810 811 cc.easeElasticIn = function (period) { 812 if(period && period !== 0.3){ 813 return { 814 _period: period, 815 easing: function (dt) { 816 if (dt === 0 || dt === 1) 817 return dt; 818 dt = dt - 1; 819 return -Math.pow(2, 10 * dt) * Math.sin((dt - (this._period / 4)) * Math.PI * 2 / this._period); 820 }, 821 /** 822 * @return {cc.EaseElasticIn} 823 */ 824 reverse:function () { 825 return cc.easeElasticOut(this._period); 826 } 827 }; 828 } 829 return cc._easeElasticInObj; 830 }; 831 832 /** 833 * Ease Elastic Out action. 834 * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. 835 * @class 836 * @extends cc.EaseElastic 837 */ 838 cc.EaseElasticOut = cc.EaseElastic.extend(/** @lends cc.EaseElasticOut# */{ 839 /** 840 * @param {Number} time1 841 */ 842 update:function (time1) { 843 var newT = 0; 844 if (time1 === 0 || time1 == 1) { 845 newT = time1; 846 } else { 847 var s = this._period / 4; 848 newT = Math.pow(2, -10 * time1) * Math.sin((time1 - s) * Math.PI * 2 / this._period) + 1; 849 } 850 851 this._inner.update(newT); 852 }, 853 854 /** 855 * @return {cc.EaseElasticIn} 856 */ 857 reverse:function () { 858 return cc.EaseElasticIn.create(this._inner.reverse(), this._period); 859 }, 860 861 clone:function(){ 862 var action = new cc.EaseElasticOut(); 863 action.initWithAction(this._inner.clone(), this._period); 864 return action; 865 } 866 }); 867 868 /** Creates the action with the inner action and the period in radians (default is 0.3) 869 * @param {cc.ActionInterval} action 870 * @param {Number} [period=0.3] 871 * @return {cc.EaseElasticOut} 872 * @example 873 * // example 874 * var moveEaseElasticOut = cc.EaseElasticOut.create(action, 3.0); 875 */ 876 cc.EaseElasticOut.create = function (action, period) { 877 return new cc.EaseElasticOut(action, period); 878 }; 879 880 //default ease elastic out object (period = 0.3) 881 cc._easeElasticOutObj = { 882 easing: function (dt) { 883 return (dt === 0 || dt === 1) ? dt : Math.pow(2, -10 * dt) * Math.sin((dt - (0.3 / 4)) * Math.PI * 2 / 0.3) + 1; 884 }, 885 reverse:function(){ 886 return cc._easeElasticInObj; 887 } 888 }; 889 890 cc.easeElasticOut = function (period) { 891 if(period && period !== 0.3){ 892 return { 893 _period: period, 894 easing: function (dt) { 895 return (dt === 0 || dt === 1) ? dt : Math.pow(2, -10 * dt) * Math.sin((dt - (this._period / 4)) * Math.PI * 2 / this._period) + 1; 896 }, 897 reverse:function(){ 898 return cc.easeElasticIn(this._period); 899 } 900 }; 901 } 902 return cc._easeElasticOutObj; 903 }; 904 905 /** 906 * Ease Elastic InOut action. 907 * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. 908 * @class 909 * @extends cc.EaseElastic 910 */ 911 cc.EaseElasticInOut = cc.EaseElastic.extend(/** @lends cc.EaseElasticInOut# */{ 912 /** 913 * @param {Number} time1 914 */ 915 update:function (time1) { 916 var newT = 0; 917 var locPeriod = this._period; 918 if (time1 === 0 || time1 == 1) { 919 newT = time1; 920 } else { 921 time1 = time1 * 2; 922 if (!locPeriod) 923 locPeriod = this._period = 0.3 * 1.5; 924 925 var s = locPeriod / 4; 926 time1 = time1 - 1; 927 if (time1 < 0) 928 newT = -0.5 * Math.pow(2, 10 * time1) * Math.sin((time1 - s) * Math.PI * 2 / locPeriod); 929 else 930 newT = Math.pow(2, -10 * time1) * Math.sin((time1 - s) * Math.PI * 2 / locPeriod) * 0.5 + 1; 931 } 932 this._inner.update(newT); 933 }, 934 935 /** 936 * @return {cc.EaseElasticInOut} 937 */ 938 reverse:function () { 939 return cc.EaseElasticInOut.create(this._inner.reverse(), this._period); 940 }, 941 942 clone:function(){ 943 var action = new cc.EaseElasticInOut(); 944 action.initWithAction(this._inner.clone(), this._period); 945 return action; 946 } 947 }); 948 949 /** Creates the action with the inner action and the period in radians (default is 0.3) 950 * @param {cc.ActionInterval} action 951 * @param {Number} [period=0.3] 952 * @return {cc.EaseElasticInOut} 953 * @example 954 * // example 955 * var moveEaseElasticInOut = cc.EaseElasticInOut.create(action, 3.0); 956 */ 957 cc.EaseElasticInOut.create = function (action, period) { 958 return new cc.EaseElasticInOut(action, period); 959 }; 960 961 cc.easeElasticInOut = function (period) { 962 period = period || 0.3; 963 return { 964 _period: period, 965 easing: function (dt) { 966 var newT = 0; 967 var locPeriod = this._period; 968 if (dt === 0 || dt === 1) { 969 newT = dt; 970 } else { 971 dt = dt * 2; 972 if (!locPeriod) 973 locPeriod = this._period = 0.3 * 1.5; 974 var s = locPeriod / 4; 975 dt = dt - 1; 976 if (dt < 0) 977 newT = -0.5 * Math.pow(2, 10 * dt) * Math.sin((dt - s) * Math.PI * 2 / locPeriod); 978 else 979 newT = Math.pow(2, -10 * dt) * Math.sin((dt - s) * Math.PI * 2 / locPeriod) * 0.5 + 1; 980 } 981 return newT; 982 }, 983 reverse: function(){ 984 return cc.easeElasticInOut(this._period); 985 } 986 }; 987 }; 988 989 /** 990 * cc.EaseBounce abstract class. 991 * @class 992 * @extends cc.ActionEase 993 */ 994 cc.EaseBounce = cc.ActionEase.extend(/** @lends cc.EaseBounce# */{ 995 /** 996 * @param {Number} time1 997 * @return {Number} 998 */ 999 bounceTime:function (time1) { 1000 if (time1 < 1 / 2.75) { 1001 return 7.5625 * time1 * time1; 1002 } else if (time1 < 2 / 2.75) { 1003 time1 -= 1.5 / 2.75; 1004 return 7.5625 * time1 * time1 + 0.75; 1005 } else if (time1 < 2.5 / 2.75) { 1006 time1 -= 2.25 / 2.75; 1007 return 7.5625 * time1 * time1 + 0.9375; 1008 } 1009 1010 time1 -= 2.625 / 2.75; 1011 return 7.5625 * time1 * time1 + 0.984375; 1012 }, 1013 1014 clone:function(){ 1015 var action = new cc.EaseBounce(); 1016 action.initWithAction(this._inner.clone()); 1017 return action; 1018 }, 1019 1020 /** 1021 * @return {cc.EaseBounce} 1022 */ 1023 reverse:function () { 1024 return cc.EaseBounce.create(this._inner.reverse()); 1025 } 1026 }); 1027 1028 /** creates an ease bounce action 1029 * @param {cc.ActionInterval} action 1030 * @return {cc.EaseBounce} 1031 * @example 1032 * // example 1033 * var moveEaseBounce = cc.EaseBounce.create(action); 1034 */ 1035 cc.EaseBounce.create = function (action) { 1036 return new cc.EaseBounce(action); 1037 }; 1038 1039 /** 1040 * cc.EaseBounceIn action. 1041 * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. 1042 * @class 1043 * @extends cc.EaseBounce 1044 */ 1045 cc.EaseBounceIn = cc.EaseBounce.extend(/** @lends cc.EaseBounceIn# */{ 1046 /** 1047 * @param {Number} time1 1048 */ 1049 update:function (time1) { 1050 var newT = 1 - this.bounceTime(1 - time1); 1051 this._inner.update(newT); 1052 }, 1053 1054 /** 1055 * @return {cc.EaseBounceOut} 1056 */ 1057 reverse:function () { 1058 return cc.EaseBounceOut.create(this._inner.reverse()); 1059 }, 1060 1061 clone:function(){ 1062 var action = new cc.EaseBounceIn(); 1063 action.initWithAction(this._inner.clone()); 1064 return action; 1065 } 1066 }); 1067 1068 /** creates the action 1069 * @param {cc.ActionInterval} action 1070 * @return {cc.EaseBounceIn} 1071 * @example 1072 * // example 1073 * var moveEaseBounceIn = cc.EaseBounceIn.create(action); 1074 */ 1075 cc.EaseBounceIn.create = function (action) { 1076 return new cc.EaseBounceIn(action); 1077 }; 1078 1079 cc._bounceTime = function (time1) { 1080 if (time1 < 1 / 2.75) { 1081 return 7.5625 * time1 * time1; 1082 } else if (time1 < 2 / 2.75) { 1083 time1 -= 1.5 / 2.75; 1084 return 7.5625 * time1 * time1 + 0.75; 1085 } else if (time1 < 2.5 / 2.75) { 1086 time1 -= 2.25 / 2.75; 1087 return 7.5625 * time1 * time1 + 0.9375; 1088 } 1089 1090 time1 -= 2.625 / 2.75; 1091 return 7.5625 * time1 * time1 + 0.984375; 1092 }; 1093 1094 cc._easeBounceInObj = { 1095 easing: function(dt){ 1096 return 1 - cc._bounceTime(1 - dt); 1097 }, 1098 reverse: function(){ 1099 return cc._easeBounceOutObj; 1100 } 1101 }; 1102 cc.easeBounceIn = function(){ 1103 return cc._easeBounceInObj; 1104 }; 1105 1106 /** 1107 * cc.EaseBounceOut action. 1108 * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. 1109 * @class 1110 * @extends cc.EaseBounce 1111 */ 1112 cc.EaseBounceOut = cc.EaseBounce.extend(/** @lends cc.EaseBounceOut# */{ 1113 /** 1114 * @param {Number} time1 1115 */ 1116 update:function (time1) { 1117 var newT = this.bounceTime(time1); 1118 this._inner.update(newT); 1119 }, 1120 1121 /** 1122 * @return {cc.ActionInterval} 1123 */ 1124 reverse:function () { 1125 return cc.EaseBounceIn.create(this._inner.reverse()); 1126 }, 1127 1128 clone:function(){ 1129 var action = new cc.EaseBounceOut(); 1130 action.initWithAction(this._inner.clone()); 1131 return action; 1132 } 1133 }); 1134 1135 /** creates the action 1136 * @param {cc.ActionInterval} action 1137 * @return {cc.EaseBounceOut} 1138 * @example 1139 * // example 1140 * var moveEaseBounceOut = cc.EaseBounceOut.create(action); 1141 */ 1142 cc.EaseBounceOut.create = function (action) { 1143 return new cc.EaseBounceOut(action); 1144 }; 1145 1146 cc._easeBounceOutObj = { 1147 easing: function(dt){ 1148 return cc._bounceTime(dt); 1149 }, 1150 reverse:function () { 1151 return cc._easeBounceInObj; 1152 } 1153 }; 1154 cc.easeBounceOut = function(){ 1155 return cc._easeBounceOutObj; 1156 }; 1157 1158 /** 1159 * cc.EaseBounceInOut action. 1160 * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. 1161 * @class 1162 * @extends cc.EaseBounce 1163 */ 1164 cc.EaseBounceInOut = cc.EaseBounce.extend(/** @lends cc.EaseBounceInOut# */{ 1165 /** 1166 * @param {Number} time1 1167 */ 1168 update:function (time1) { 1169 var newT = 0; 1170 if (time1 < 0.5) { 1171 time1 = time1 * 2; 1172 newT = (1 - this.bounceTime(1 - time1)) * 0.5; 1173 } else { 1174 newT = this.bounceTime(time1 * 2 - 1) * 0.5 + 0.5; 1175 } 1176 this._inner.update(newT); 1177 }, 1178 1179 clone:function(){ 1180 var action = new cc.EaseBounceInOut(); 1181 action.initWithAction(this._inner.clone()); 1182 return action; 1183 }, 1184 1185 /** 1186 * @return {cc.EaseBounceInOut} 1187 */ 1188 reverse:function () { 1189 return cc.EaseBounceInOut.create(this._inner.reverse()); 1190 } 1191 }); 1192 1193 /** creates the action 1194 * @param {cc.ActionInterval} action 1195 * @return {cc.EaseBounceInOut} 1196 * @example 1197 * // example 1198 * var moveEaseBounceInOut = cc.EaseBounceInOut.create(action); 1199 */ 1200 cc.EaseBounceInOut.create = function (action) { 1201 return new cc.EaseBounceInOut(action); 1202 }; 1203 1204 cc._easeBounceInOutObj = { 1205 easing: function (time1) { 1206 var newT; 1207 if (time1 < 0.5) { 1208 time1 = time1 * 2; 1209 newT = (1 - cc._bounceTime(1 - time1)) * 0.5; 1210 } else { 1211 newT = cc._bounceTime(time1 * 2 - 1) * 0.5 + 0.5; 1212 } 1213 return newT; 1214 }, 1215 reverse: function(){ 1216 return cc._easeBounceInOutObj; 1217 } 1218 }; 1219 1220 cc.easeBounceInOut = function(){ 1221 return cc._easeBounceInOutObj; 1222 }; 1223 1224 /** 1225 * cc.EaseBackIn action. 1226 * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. 1227 * @class 1228 * @extends cc.ActionEase 1229 */ 1230 cc.EaseBackIn = cc.ActionEase.extend(/** @lends cc.EaseBackIn# */{ 1231 /** 1232 * @param {Number} time1 1233 */ 1234 update:function (time1) { 1235 var overshoot = 1.70158; 1236 time1 = time1===0 || time1==1 ? time1 : time1 * time1 * ((overshoot + 1) * time1 - overshoot); 1237 this._inner.update(time1); 1238 }, 1239 1240 /** 1241 * @return {cc.EaseBackOut} 1242 */ 1243 reverse:function () { 1244 return cc.EaseBackOut.create(this._inner.reverse()); 1245 }, 1246 1247 clone:function(){ 1248 var action = new cc.EaseBackIn(); 1249 action.initWithAction(this._inner.clone()); 1250 return action; 1251 } 1252 }); 1253 1254 1255 /** creates the action 1256 * @param {cc.ActionInterval} action 1257 * @return {cc.EaseBackIn} 1258 * @example 1259 * // example 1260 * var moveEaseBackIn = cc.EaseBackIn.create(action); 1261 */ 1262 cc.EaseBackIn.create = function (action) { 1263 return new cc.EaseBackIn(action); 1264 }; 1265 1266 cc._easeBackInObj = { 1267 easing: function (time1) { 1268 var overshoot = 1.70158; 1269 return (time1===0 || time1===1) ? time1 : time1 * time1 * ((overshoot + 1) * time1 - overshoot); 1270 }, 1271 reverse: function(){ 1272 return cc._easeBackOutObj; 1273 } 1274 }; 1275 1276 cc.easeBackIn = function(){ 1277 return cc._easeBackInObj; 1278 }; 1279 1280 /** 1281 * cc.EaseBackOut action. 1282 * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. 1283 * @class 1284 * @extends cc.ActionEase 1285 */ 1286 cc.EaseBackOut = cc.ActionEase.extend(/** @lends cc.EaseBackOut# */{ 1287 /** 1288 * @param {Number} time1 1289 */ 1290 update:function (time1) { 1291 var overshoot = 1.70158; 1292 time1 = time1 - 1; 1293 this._inner.update(time1 * time1 * ((overshoot + 1) * time1 + overshoot) + 1); 1294 }, 1295 1296 /** 1297 * @return {cc.EaseBackIn} 1298 */ 1299 reverse:function () { 1300 return cc.EaseBackIn.create(this._inner.reverse()); 1301 }, 1302 1303 clone:function(){ 1304 var action = new cc.EaseBackOut(); 1305 action.initWithAction(this._inner.clone()); 1306 return action; 1307 } 1308 }); 1309 1310 /** creates the action 1311 * @param {cc.ActionInterval} action 1312 * @return {cc.EaseBackOut} 1313 * @example 1314 * // example 1315 * var moveEaseBackOut = cc.EaseBackOut.create(action); 1316 */ 1317 cc.EaseBackOut.create = function (action) { 1318 return new cc.EaseBackOut(action); 1319 }; 1320 1321 cc._easeBackOutObj = { 1322 easing: function (time1) { 1323 var overshoot = 1.70158; 1324 time1 = time1 - 1; 1325 return time1 * time1 * ((overshoot + 1) * time1 + overshoot) + 1; 1326 }, 1327 reverse: function(){ 1328 return cc._easeBackInObj; 1329 } 1330 }; 1331 1332 cc.easeBackOut = function(){ 1333 return cc._easeBackOutObj; 1334 }; 1335 1336 /** 1337 * cc.EaseBackInOut action. 1338 * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action. 1339 * @class 1340 * @extends cc.ActionEase 1341 */ 1342 cc.EaseBackInOut = cc.ActionEase.extend(/** @lends cc.EaseBackInOut# */{ 1343 /** 1344 * @param {Number} time1 1345 */ 1346 update:function (time1) { 1347 var overshoot = 1.70158 * 1.525; 1348 time1 = time1 * 2; 1349 if (time1 < 1) { 1350 this._inner.update((time1 * time1 * ((overshoot + 1) * time1 - overshoot)) / 2); 1351 } else { 1352 time1 = time1 - 2; 1353 this._inner.update((time1 * time1 * ((overshoot + 1) * time1 + overshoot)) / 2 + 1); 1354 } 1355 }, 1356 1357 clone:function(){ 1358 var action = new cc.EaseBackInOut(); 1359 action.initWithAction(this._inner.clone()); 1360 return action; 1361 }, 1362 1363 /** 1364 * @return {cc.EaseBackInOut} 1365 */ 1366 reverse:function () { 1367 return cc.EaseBackInOut.create(this._inner.reverse()); 1368 } 1369 }); 1370 1371 1372 /** creates the action 1373 * @param {cc.ActionInterval} action 1374 * @return {cc.EaseBackInOut} 1375 * @example 1376 * // example 1377 * var moveEaseBackInOut = cc.EaseBackInOut.create(action); 1378 */ 1379 cc.EaseBackInOut.create = function (action) { 1380 return new cc.EaseBackInOut(action); 1381 }; 1382 1383 cc._easeBackInOutObj = { 1384 easing: function (time1) { 1385 var overshoot = 1.70158 * 1.525; 1386 time1 = time1 * 2; 1387 if (time1 < 1) { 1388 return (time1 * time1 * ((overshoot + 1) * time1 - overshoot)) / 2; 1389 } else { 1390 time1 = time1 - 2; 1391 return (time1 * time1 * ((overshoot + 1) * time1 + overshoot)) / 2 + 1; 1392 } 1393 }, 1394 reverse: function(){ 1395 return cc._easeBackInOutObj; 1396 } 1397 }; 1398 1399 cc.easeBackInOut = function(){ 1400 return cc._easeBackInOutObj; 1401 }; 1402 1403 /** 1404 * cc.EaseBezierAction action. 1405 * @type {Function|*} 1406 */ 1407 cc.EaseBezierAction = cc.ActionEase.extend(/** @lends cc.EaseBezierAction# */{ 1408 1409 _p0: null, 1410 _p1: null, 1411 _p2: null, 1412 _p3: null, 1413 1414 ctor: function(action){ 1415 cc.ActionEase.prototype.ctor.call(this, action); 1416 }, 1417 1418 _updateTime: function(a, b, c, d, t){ 1419 return (Math.pow(1-t,3) * a + 3*t*(Math.pow(1-t,2))*b + 3*Math.pow(t,2)*(1-t)*c + Math.pow(t,3)*d ); 1420 }, 1421 1422 update: function(time){ 1423 var t = this._updateTime(this._p0, this._p1, this._p2, this._p3, time); 1424 this._inner.update(t); 1425 }, 1426 clone: function(){ 1427 var action = new cc.EaseBezierAction(); 1428 action.initWithAction(this._inner.clone()); 1429 action.setBezierParamer(this._p0, this._p1, this._p2, this._p3); 1430 return action; 1431 }, 1432 reverse: function(){ 1433 var action = cc.EaseBezierAction.create(this._inner.reverse()); 1434 action.setBezierParamer(this._p3, this._p2, this._p1, this._p0); 1435 return action; 1436 }, 1437 setBezierParamer: function(p0, p1, p2, p3){ 1438 this._p0 = p0 || 0; 1439 this._p1 = p1 || 0; 1440 this._p2 = p2 || 0; 1441 this._p3 = p3 || 0; 1442 } 1443 }); 1444 1445 /** 1446 * creates the action 1447 * @param action 1448 * @returns {cc.EaseQuadraticActionIn} 1449 */ 1450 cc.EaseBezierAction.create = function(action){ 1451 return new cc.EaseBezierAction(action); 1452 }; 1453 1454 cc.easeBezierAction = function(p0, p1, p2, p3){ 1455 return { 1456 easing: function(time){ 1457 return cc.EaseBezierAction.prototype._updateTime(p0, p1, p2, p3, time); 1458 }, 1459 reverse: function(){ 1460 return cc.easeBezierAction(p3, p2, p1, p0); 1461 } 1462 }; 1463 }; 1464 1465 1466 /** 1467 * cc.EaseQuadraticActionIn action. 1468 * @type {Function|*} 1469 */ 1470 cc.EaseQuadraticActionIn = cc.ActionEase.extend(/** @lends cc.EaseQuadraticActionIn# */{ 1471 1472 _updateTime: function(time){ 1473 return Math.pow(time, 2); 1474 }, 1475 1476 update: function(time){ 1477 this._inner.update(this._updateTime(time)); 1478 }, 1479 1480 clone: function(){ 1481 var action = new cc.EaseQuadraticActionIn(); 1482 action.initWithAction(this._inner.clone()); 1483 return action; 1484 }, 1485 1486 reverse: function(){ 1487 return cc.EaseQuadraticActionIn.create(this._inner.reverse()); 1488 } 1489 1490 }); 1491 1492 /** 1493 * creates the action 1494 * @param action 1495 * @returns {cc.EaseQuadraticActionIn} 1496 */ 1497 cc.EaseQuadraticActionIn.create = function(action){ 1498 return new cc.EaseQuadraticActionIn(action); 1499 }; 1500 1501 cc._easeQuadraticActionIn = { 1502 easing: cc.EaseQuadraticActionIn.prototype._updateTime, 1503 reverse: function(){ 1504 return cc._easeQuadraticActionIn; 1505 } 1506 }; 1507 1508 cc.easeQuadraticActionIn = function(){ 1509 return cc._easeQuadraticActionIn; 1510 }; 1511 1512 /** 1513 * cc.EaseQuadraticActionIn action. 1514 * @type {Function|*} 1515 */ 1516 cc.EaseQuadraticActionOut = cc.ActionEase.extend(/** @lends cc.EaseQuadraticActionOut# */{ 1517 1518 _updateTime: function(time){ 1519 return -time*(time-2); 1520 }, 1521 1522 update: function(time){ 1523 this._inner.update(this._updateTime(time)); 1524 }, 1525 clone: function(){ 1526 var action = new cc.EaseQuadraticActionOut(); 1527 action.initWithAction(); 1528 return action; 1529 }, 1530 reverse: function(){ 1531 return cc.EaseQuadraticActionOut.create(this._inner.reverse()); 1532 } 1533 }); 1534 1535 /** 1536 * creates the action 1537 * @param action 1538 * @returns {cc.EaseQuadraticActionOut} 1539 */ 1540 cc.EaseQuadraticActionOut.create = function(action){ 1541 return new cc.EaseQuadraticActionOut(action); 1542 }; 1543 1544 cc._easeQuadraticActionOut = { 1545 easing: cc.EaseQuadraticActionOut.prototype._updateTime, 1546 reverse: function(){ 1547 return cc._easeQuadraticActionOut; 1548 } 1549 }; 1550 1551 cc.easeQuadraticActionOut = function(){ 1552 return cc._easeQuadraticActionOut; 1553 }; 1554 1555 /** 1556 * cc.EaseQuadraticActionInOut action. 1557 * @type {Function|*} 1558 */ 1559 cc.EaseQuadraticActionInOut = cc.ActionEase.extend(/** @lends cc.EaseQuadraticActionInOut# */{ 1560 _updateTime: function(time){ 1561 var resultTime = time; 1562 time *= 2; 1563 if(time < 1){ 1564 resultTime = time * time * 0.5; 1565 }else{ 1566 --time; 1567 resultTime = -0.5 * ( time * ( time - 2 ) - 1) 1568 } 1569 return resultTime; 1570 }, 1571 update: function(time){ 1572 this._inner.update(this._updateTime(time)); 1573 }, 1574 clone: function(){ 1575 var action = new cc.EaseQuadraticActionInOut(); 1576 action.initWithAction(this._inner.clone()); 1577 return action; 1578 }, 1579 reverse: function(){ 1580 return cc.EaseQuadraticActionInOut.create(this._inner.reverse()); 1581 } 1582 }); 1583 1584 /** 1585 * creates the action 1586 * @param action 1587 * @returns {cc.EaseQuadraticActionOut} 1588 */ 1589 cc.EaseQuadraticActionInOut.create = function(action){ 1590 return new cc.EaseQuadraticActionInOut(action); 1591 }; 1592 1593 cc._easeQuadraticActionInOut = { 1594 easing: cc.EaseQuadraticActionInOut.prototype._updateTime, 1595 reverse: function(){ 1596 return cc._easeQuadraticActionInOut; 1597 } 1598 }; 1599 1600 cc.easeQuadraticActionInOut = function(){ 1601 return cc._easeQuadraticActionInOut; 1602 }; 1603 1604 /** 1605 * cc.EaseQuarticActionIn action. 1606 * @type {Function|*} 1607 */ 1608 cc.EaseQuarticActionIn = cc.ActionEase.extend(/** @lends cc.EaseQuarticActionIn# */{ 1609 _updateTime: function(time){ 1610 return time * time * time * time; 1611 }, 1612 update: function(time){ 1613 this._inner.update(this._updateTime(time)); 1614 }, 1615 clone: function(){ 1616 var action = new cc.EaseQuarticActionIn(); 1617 action.initWithAction(this._inner.clone()); 1618 return action; 1619 }, 1620 reverse: function(){ 1621 return cc.EaseQuarticActionIn.create(this._inner.reverse()); 1622 } 1623 }); 1624 1625 /** 1626 * creates the action 1627 * @param action 1628 * @returns {cc.EaseQuadraticActionOut} 1629 */ 1630 cc.EaseQuarticActionIn.create = function(action){ 1631 return new cc.EaseQuarticActionIn(action); 1632 }; 1633 1634 cc._easeQuarticActionIn = { 1635 easing: cc.EaseQuarticActionIn.prototype._updateTime, 1636 reverse: function(){ 1637 return cc._easeQuarticActionIn; 1638 } 1639 }; 1640 1641 cc.easeQuarticActionIn = function(){ 1642 return cc._easeQuarticActionIn; 1643 }; 1644 1645 /** 1646 * cc.EaseQuarticActionOut action. 1647 * @type {Function|*} 1648 */ 1649 cc.EaseQuarticActionOut = cc.ActionEase.extend(/** @lends cc.EaseQuarticActionOut# */{ 1650 _updateTime: function(time){ 1651 time -= 1; 1652 return -(time * time * time * time - 1); 1653 }, 1654 update: function(time){ 1655 this._inner.update(this._updateTime(time)); 1656 }, 1657 clone: function(){ 1658 var action = new cc.EaseQuarticActionOut(); 1659 action.initWithAction(this._inner.clone()); 1660 return action; 1661 }, 1662 reverse: function(){ 1663 return cc.EaseQuarticActionOut.create(this._inner.reverse()); 1664 } 1665 }); 1666 1667 /** 1668 * creates the action 1669 * @param action 1670 * @returns {cc.EaseQuadraticActionOut} 1671 */ 1672 cc.EaseQuarticActionOut.create = function(action){ 1673 return new cc.EaseQuarticActionOut(action); 1674 }; 1675 1676 cc._easeQuarticActionOut = { 1677 easing: cc.EaseQuarticActionOut.prototype._updateTime, 1678 reverse: function(){ 1679 return cc._easeQuarticActionOut; 1680 } 1681 }; 1682 1683 cc.easeQuarticActionOut = function(){ 1684 return cc._easeQuarticActionOut; 1685 }; 1686 1687 /** 1688 * cc.EaseQuarticActionInOut action. 1689 * @type {Function|*} 1690 */ 1691 cc.EaseQuarticActionInOut = cc.ActionEase.extend(/** @lends cc.EaseQuarticActionInOut# */{ 1692 _updateTime: function(time){ 1693 time = time*2; 1694 if (time < 1) 1695 return 0.5 * time * time * time * time; 1696 time -= 2; 1697 return -0.5 * (time * time * time * time - 2); 1698 }, 1699 update: function(time){ 1700 this._inner.update(this._updateTime(time)); 1701 }, 1702 clone: function(){ 1703 var action = new cc.EaseQuarticActionInOut(); 1704 action.initWithAction(this._inner.clone()); 1705 return action; 1706 }, 1707 reverse: function(){ 1708 return cc.EaseQuarticActionInOut.create(this._inner.reverse()); 1709 } 1710 }); 1711 1712 /** 1713 * creates the action 1714 * @param action 1715 * @returns {cc.EaseQuadraticActionOut} 1716 */ 1717 cc.EaseQuarticActionInOut.create = function(action){ 1718 return new cc.EaseQuarticActionInOut(action); 1719 }; 1720 1721 cc._easeQuarticActionInOut = { 1722 easing: cc.EaseQuarticActionInOut.prototype._updateTime, 1723 reverse: function(){ 1724 return cc._easeQuarticActionInOut; 1725 } 1726 }; 1727 1728 cc.easeQuarticActionInOut = function(){ 1729 return cc._easeQuarticActionInOut; 1730 }; 1731 1732 /** 1733 * cc.EaseQuinticActionIn action. 1734 * @type {Function|*} 1735 */ 1736 cc.EaseQuinticActionIn = cc.ActionEase.extend(/** @lends cc.EaseQuinticActionIn# */{ 1737 _updateTime: function(time){ 1738 return time * time * time * time * time; 1739 }, 1740 update: function(time){ 1741 this._inner.update(this._updateTime(time)); 1742 }, 1743 clone: function(){ 1744 var action = new cc.EaseQuinticActionIn(); 1745 action.initWithAction(this._inner.clone()); 1746 return action; 1747 }, 1748 reverse: function(){ 1749 return cc.EaseQuinticActionIn.create(this._inner.reverse()); 1750 } 1751 }); 1752 1753 /** 1754 * creates the action 1755 * @param action 1756 * @returns {cc.EaseQuadraticActionOut} 1757 */ 1758 cc.EaseQuinticActionIn.create = function(action){ 1759 return new cc.EaseQuinticActionIn(action); 1760 }; 1761 1762 cc._easeQuinticActionIn = { 1763 easing: cc.EaseQuinticActionIn.prototype._updateTime, 1764 reverse: function(){ 1765 return cc._easeQuinticActionIn; 1766 } 1767 }; 1768 1769 cc.easeQuinticActionIn = function(){ 1770 return cc._easeQuinticActionIn; 1771 }; 1772 1773 /** 1774 * cc.EaseQuinticActionOut action. 1775 * @type {Function|*} 1776 */ 1777 cc.EaseQuinticActionOut = cc.ActionEase.extend(/** @lends cc.EaseQuinticActionOut# */{ 1778 _updateTime: function(time){ 1779 time -=1; 1780 return (time * time * time * time * time + 1); 1781 }, 1782 update: function(time){ 1783 this._inner.update(this._updateTime(time)); 1784 }, 1785 clone: function(){ 1786 var action = new cc.EaseQuinticActionOut(); 1787 action.initWithAction(this._inner.clone()); 1788 return action; 1789 }, 1790 reverse: function(){ 1791 return cc.EaseQuinticActionOut.create(this._inner.reverse()); 1792 } 1793 }); 1794 1795 /** 1796 * creates the action 1797 * @param action 1798 * @returns {cc.EaseQuadraticActionOut} 1799 */ 1800 cc.EaseQuinticActionOut.create = function(action){ 1801 return new cc.EaseQuinticActionOut(action); 1802 }; 1803 1804 cc._easeQuinticActionOut = { 1805 easing: cc.EaseQuinticActionOut.prototype._updateTime, 1806 reverse: function(){ 1807 return cc._easeQuinticActionOut; 1808 } 1809 }; 1810 1811 cc.easeQuinticActionOut = function(){ 1812 return cc._easeQuinticActionOut; 1813 }; 1814 1815 /** 1816 * cc.EaseQuinticActionInOut action. 1817 * @type {Function|*} 1818 */ 1819 cc.EaseQuinticActionInOut = cc.ActionEase.extend(/** @lends cc.EaseQuinticActionInOut# */{ 1820 _updateTime: function(time){ 1821 time = time*2; 1822 if (time < 1) 1823 return 0.5 * time * time * time * time * time; 1824 time -= 2; 1825 return 0.5 * (time * time * time * time * time + 2); 1826 }, 1827 update: function(time){ 1828 this._inner.update(this._updateTime(time)); 1829 }, 1830 clone: function(){ 1831 var action = new cc.EaseQuinticActionInOut(); 1832 action.initWithAction(this._inner.clone()); 1833 return action; 1834 }, 1835 reverse: function(){ 1836 return cc.EaseQuinticActionInOut.create(this._inner.reverse()); 1837 } 1838 }); 1839 1840 /** 1841 * creates the action 1842 * @param action 1843 * @returns {cc.EaseQuadraticActionOut} 1844 */ 1845 cc.EaseQuinticActionInOut.create = function(action){ 1846 return new cc.EaseQuinticActionInOut(action); 1847 }; 1848 1849 cc._easeQuinticActionInOut = { 1850 easing: cc.EaseQuinticActionInOut.prototype._updateTime, 1851 reverse: function(){ 1852 return cc._easeQuinticActionInOut; 1853 } 1854 }; 1855 1856 cc.easeQuinticActionInOut = function(){ 1857 return cc._easeQuinticActionInOut; 1858 }; 1859 1860 /** 1861 * cc.EaseCircleActionIn action. 1862 * @type {Function|*} 1863 */ 1864 cc.EaseCircleActionIn = cc.ActionEase.extend(/** @lends cc.EaseCircleActionIn# */{ 1865 _updateTime: function(time){ 1866 return -1 * (Math.sqrt(1 - time * time) - 1); 1867 }, 1868 update: function(time){ 1869 this._inner.update(this._updateTime(time)); 1870 }, 1871 clone: function(){ 1872 var action = new cc.EaseCircleActionIn(); 1873 action.initWithAction(this._inner.clone()); 1874 return action; 1875 }, 1876 reverse: function(){ 1877 return cc.EaseCircleActionIn.create(this._inner.reverse()); 1878 } 1879 }); 1880 1881 /** 1882 * creates the action 1883 * @param action 1884 * @returns {cc.EaseQuadraticActionOut} 1885 */ 1886 cc.EaseCircleActionIn.create = function(action){ 1887 return new cc.EaseCircleActionIn(action); 1888 }; 1889 1890 cc._easeCircleActionIn = { 1891 easing: cc.EaseCircleActionIn.prototype._updateTime, 1892 reverse: function(){ 1893 return cc._easeCircleActionIn; 1894 } 1895 }; 1896 1897 cc.easeCircleActionIn = function(){ 1898 return cc._easeCircleActionIn; 1899 }; 1900 1901 /** 1902 * cc.EaseCircleActionOut action. 1903 * @type {Function|*} 1904 */ 1905 cc.EaseCircleActionOut = cc.ActionEase.extend(/** @lends cc.EaseCircleActionOut# */{ 1906 _updateTime: function(time){ 1907 time = time - 1; 1908 return Math.sqrt(1 - time * time); 1909 }, 1910 update: function(time){ 1911 this._inner.update(this._updateTime(time)); 1912 }, 1913 clone: function(){ 1914 var action = new cc.EaseCircleActionOut(); 1915 action.initWithAction(this._inner.clone()); 1916 return action; 1917 }, 1918 reverse: function(){ 1919 return cc.EaseCircleActionOut.create(this._inner.reverse()); 1920 } 1921 }); 1922 1923 /** 1924 * creates the action 1925 * @param action 1926 * @returns {cc.EaseQuadraticActionOut} 1927 */ 1928 cc.EaseCircleActionOut.create = function(action){ 1929 return new cc.EaseCircleActionOut(action); 1930 }; 1931 1932 cc._easeCircleActionOut = { 1933 easing: cc.EaseCircleActionOut.prototype._updateTime, 1934 reverse: function(){ 1935 return cc._easeCircleActionOut; 1936 } 1937 }; 1938 1939 cc.easeCircleActionOut = function(){ 1940 return cc._easeCircleActionOut; 1941 }; 1942 1943 /** 1944 * cc.EaseCircleActionInOut action. 1945 * @type {Function|*} 1946 */ 1947 cc.EaseCircleActionInOut = cc.ActionEase.extend(/** @lends cc.EaseCircleActionInOut# */{ 1948 _updateTime: function(time){ 1949 time = time * 2; 1950 if (time < 1) 1951 return -0.5 * (Math.sqrt(1 - time * time) - 1); 1952 time -= 2; 1953 return 0.5 * (Math.sqrt(1 - time * time) + 1); 1954 }, 1955 update: function(time){ 1956 this._inner.update(this._updateTime(time)); 1957 }, 1958 clone: function(){ 1959 var action = new cc.EaseCircleActionInOut(); 1960 action.initWithAction(this._inner.clone()); 1961 return action; 1962 }, 1963 reverse: function(){ 1964 return cc.EaseCircleActionInOut.create(this._inner.reverse()); 1965 } 1966 }); 1967 1968 /** 1969 * creates the action 1970 * @param action 1971 * @returns {cc.EaseQuadraticActionOut} 1972 */ 1973 cc.EaseCircleActionInOut.create = function(action){ 1974 return new cc.EaseCircleActionInOut(action); 1975 }; 1976 1977 cc._easeCircleActionInOut = { 1978 easing: cc.EaseCircleActionInOut.prototype._updateTime, 1979 reverse: function(){ 1980 return cc._easeCircleActionInOut; 1981 } 1982 }; 1983 1984 cc.easeCircleActionInOut = function(){ 1985 return cc._easeCircleActionInOut; 1986 }; 1987 1988 /** 1989 * cc.EaseCubicActionIn action. 1990 * @type {Function|*} 1991 */ 1992 cc.EaseCubicActionIn = cc.ActionEase.extend(/** @lends cc.EaseCubicActionIn# */{ 1993 _updateTime: function(time){ 1994 return time * time * time; 1995 }, 1996 update: function(time){ 1997 this._inner.update(this._updateTime(time)); 1998 }, 1999 clone: function(){ 2000 var action = new cc.EaseCubicActionIn(); 2001 action.initWithAction(this._inner.clone()); 2002 return action; 2003 }, 2004 reverse: function(){ 2005 return cc.EaseCubicActionIn.create(this._inner.reverse()); 2006 } 2007 }); 2008 2009 /** 2010 * creates the action 2011 * @param action 2012 * @returns {cc.EaseQuadraticActionOut} 2013 */ 2014 cc.EaseCubicActionIn.create = function(action){ 2015 return new cc.EaseCubicActionIn(action); 2016 }; 2017 2018 cc._easeCubicActionIn = { 2019 easing: cc.EaseCubicActionIn.prototype._updateTime, 2020 reverse: function(){ 2021 return cc._easeCubicActionIn; 2022 } 2023 }; 2024 2025 cc.easeCubicActionIn = function(){ 2026 return cc._easeCubicActionIn; 2027 }; 2028 2029 /** 2030 * cc.EaseCubicActionOut action. 2031 * @type {Function|*} 2032 */ 2033 cc.EaseCubicActionOut = cc.ActionEase.extend(/** @lends cc.EaseCubicActionOut# */{ 2034 _updateTime: function(time){ 2035 time -= 1; 2036 return (time * time * time + 1); 2037 }, 2038 update: function(time){ 2039 this._inner.update(this._updateTime(time)); 2040 }, 2041 clone: function(){ 2042 var action = new cc.EaseCubicActionOut(); 2043 action.initWithAction(this._inner.clone()); 2044 return action; 2045 }, 2046 reverse: function(){ 2047 return cc.EaseCubicActionOut.create(this._inner.reverse()); 2048 } 2049 }); 2050 2051 /** 2052 * creates the action 2053 * @param action 2054 * @returns {cc.EaseQuadraticActionOut} 2055 */ 2056 cc.EaseCubicActionOut.create = function(action){ 2057 return new cc.EaseCubicActionOut(action); 2058 }; 2059 2060 cc._easeCubicActionOut = { 2061 easing: cc.EaseCubicActionOut.prototype._updateTime, 2062 reverse: function(){ 2063 return cc._easeCubicActionOut; 2064 } 2065 }; 2066 2067 cc.easeCubicActionOut = function(){ 2068 return cc._easeCubicActionOut; 2069 }; 2070 2071 2072 /** 2073 * cc.EaseCubicActionInOut action. 2074 * @type {Function|*} 2075 */ 2076 cc.EaseCubicActionInOut = cc.ActionEase.extend(/** @lends cc.EaseCubicActionInOut# */{ 2077 _updateTime: function(time){ 2078 time = time*2; 2079 if (time < 1) 2080 return 0.5 * time * time * time; 2081 time -= 2; 2082 return 0.5 * (time * time * time + 2); 2083 }, 2084 update: function(time){ 2085 this._inner.update(this._updateTime(time)); 2086 }, 2087 clone: function(){ 2088 var action = new cc.EaseCubicActionInOut(); 2089 action.initWithAction(this._inner.clone()); 2090 return action; 2091 }, 2092 reverse: function(){ 2093 return cc.EaseCubicActionInOut.create(this._inner.reverse()); 2094 } 2095 }); 2096 2097 /** 2098 * creates the action 2099 * @param action 2100 * @returns {cc.EaseQuadraticActionOut} 2101 */ 2102 cc.EaseCubicActionInOut.create = function(action){ 2103 return new cc.EaseCubicActionInOut(action); 2104 }; 2105 2106 cc._easeCubicActionInOut = { 2107 easing: cc.EaseCubicActionInOut.prototype._updateTime, 2108 reverse: function(){ 2109 return cc._easeCubicActionInOut; 2110 } 2111 }; 2112 2113 cc.easeCubicActionInOut = function(){ 2114 return cc._easeCubicActionInOut; 2115 }; 2116 2117