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