1 /****************************************************************************
  2  Copyright (c) 2013-2014 Chukong Technologies Inc.
  3 
  4  http://www.cocos2d-x.org
  5 
  6  Permission is hereby granted, free of charge, to any person obtaining a copy
  7  of this software and associated documentation files (the "Software"), to deal
  8  in the Software without restriction, including without limitation the rights
  9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 10  copies of the Software, and to permit persons to whom the Software is
 11  furnished to do so, subject to the following conditions:
 12 
 13  The above copyright notice and this permission notice shall be included in
 14  all copies or substantial portions of the Software.
 15 
 16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 22  THE SOFTWARE.
 23  ****************************************************************************/
 24 
 25 /**
 26  * Timeline Frame.
 27  * base class
 28  * @class
 29  */
 30 ccs.Frame = ccs.Class.extend({
 31 
 32     _frameIndex: null,
 33     _tween: null,
 34     _timeline: null,
 35     _node: null,
 36     _tweenType: null,
 37     _easingParam: null,
 38     _enterWhenPassed: null,
 39 
 40     ctor: function(){
 41         this._frameIndex = 0;
 42         this._tween = true;
 43         this._timeline = null;
 44         this._node = null;
 45         this._enterWhenPassed = false;
 46         this._easingParam = [];
 47     },
 48 
 49     _emitEvent: function(){
 50         if (this._timeline){
 51             this._timeline.getActionTimeline()._emitFrameEvent(this);
 52         }
 53     },
 54 
 55     _cloneProperty: function(frame){
 56         this._frameIndex = frame.getFrameIndex();
 57         this._tween = frame.isTween();
 58         this._tweenType = frame.getTweenType();
 59         this.setEasingParams(frame.getEasingParams());
 60     },
 61 
 62     /**
 63      * Set the frame index
 64      * @param {number} frameIndex
 65      */
 66     setFrameIndex: function(frameIndex){
 67         this._frameIndex = frameIndex;
 68     },
 69 
 70     /**
 71      * Get the frame index
 72      * @returns {null}
 73      */
 74     getFrameIndex: function(){
 75         return this._frameIndex;
 76     },
 77 
 78     /**
 79      * Set timeline
 80      * @param timeline
 81      */
 82     setTimeline: function(timeline){
 83         this._timeline = timeline;
 84     },
 85 
 86     /**
 87      * Get timeline
 88      * @param timeline
 89      * @returns {ccs.timeline}
 90      */
 91     getTimeline: function(timeline){
 92         return this._timeline;
 93     },
 94 
 95     /**
 96      * Set Node
 97      * @param {cc.Node} node
 98      */
 99     setNode: function(node){
100         this._node = node;
101     },
102 
103     /**
104      * gets the Node
105      * @return node
106      */
107     getNode: function(){
108         return this._node;
109     },
110 
111     /**
112      * set tween
113      * @param tween
114      */
115     setTween: function(tween){
116         this._tween = tween;
117     },
118 
119     /**
120      * Gets the tween
121      * @returns {boolean | null}
122      */
123     isTween: function(){
124         return this._tween;
125     },
126 
127     /**
128      * the execution of the callback
129      * @override
130      * @param {ccs.Frame} nextFrame
131      */
132     onEnter: function(nextFrame){ // = 0
133     },
134 
135     /**
136      * Each frame logic
137      * @override
138      * @param {number} percent
139      */
140     apply: function(percent){
141         if(!this._tween)
142             return;
143         if(this._tweenType !== ccs.FrameEaseType.TWEEN_EASING_MAX  && this._tweenType !==  ccs.FrameEaseType.LINEAR)
144             percent = this.tweenPercent(percent);
145         this._onApply(percent);
146     },
147 
148     _onApply: function(percent){
149 
150     },
151 
152     /**
153      * to copy object with deep copy.
154      * returns a clone of action.
155      * @override
156      * @return {ccs.Frame}
157      */
158     clone: function(){ // = 0
159     },
160 
161     tweenPercent: function(percent){
162         var func = ccs.Frame.tweenToMap[this._tweenType];
163         if(func)
164             return func(percent, this._easingParam);
165         else
166             return percent;
167     },
168 
169     setEasingParams: function(easingParams){
170         if(easingParams){
171             this._easingParam.length = 0;
172             for(var i=0; i<easingParams.length; i++)
173                 this._easingParam[i] = easingParams[i];
174         }
175     },
176 
177     getEasingParams: function(){
178         return this._easingParam;
179     },
180 
181     setTweenType: function(tweenType){
182         this._tweenType = tweenType;
183     },
184 
185     getTweenType: function(){
186         return this._tweenType;
187     },
188 
189     isEnterWhenPassed: function(){
190         return this._enterWhenPassed;
191     }
192 });
193 
194 ccs.Frame.tweenToMap = {
195     "-1": function(time, easingParam){
196         if (easingParam)
197         {
198             var tt = 1 - time;
199             return easingParam[1]*tt*tt*tt + 3*easingParam[3]*time*tt*tt + 3*easingParam[5]*time*time*tt + easingParam[7]*time*time*time;
200         }
201         return time;
202     },
203     1: cc._easeSineInObj.easing,//Sine_EaseIn
204     2: cc._easeSineOutObj.easing,//Sine_EaseOut
205     3: cc._easeSineInOutObj.easing,//Sine_EaseInOut
206 
207     4: cc._easeQuadraticActionIn.easing,//Quad_EaseIn
208     5: cc._easeQuadraticActionOut.easing,//Quad_EaseOut
209     6: cc._easeQuadraticActionInOut.easing,//Quad_EaseInOut
210 
211     7: cc._easeCubicActionIn.easing, //Cubic_EaseIn
212     8: cc._easeCubicActionOut.easing,//Cubic_EaseOut
213     9: cc._easeCubicActionInOut.easing,//Cubic_EaseInOut
214 
215     10: cc._easeCubicActionIn.easing,//Cubic_EaseIn
216     11: cc._easeCubicActionOut.easing,//Cubic_EaseOut
217     12: cc._easeCubicActionInOut.easing,//Cubic_EaseInOut
218 
219     13: cc._easeQuinticActionIn.easing,//Quint_EaseIn
220     14: cc._easeQuinticActionOut.easing,//Quint_EaseOut
221     15: cc._easeQuinticActionInOut.easing,//Quint_EaseInOut
222 
223     16: cc._easeExponentialInObj.easing,//Expo_EaseIn
224     17: cc._easeExponentialOutObj.easing,//Expo_EaseOut
225     18: cc._easeExponentialInOutObj.easing,//Expo_EaseInOut
226 
227     19: cc._easeCircleActionIn.easing,//Circ_EaseIn
228     20: cc._easeCircleActionOut.easing,//Circ_EaseOut
229     21: cc._easeCircleActionInOut.easing,//Circ_EaseInOut
230 
231     22: function(time, easingParam){
232         var period = 0.3;
233         easingParam != null && ( period = easingParam[0] );
234         return cc.easeElasticIn(period).easing(time);
235     },//Elastic_EaesIn
236     23: function(time, easingParam){
237         var period = 0.3;
238         easingParam != null && ( period = easingParam[0] );
239         return cc.easeElasticOut(period).easing(time);
240     },//Elastic_EaesOut
241     24: function(time, easingParam){
242         var period = 0.3;
243         easingParam != null && ( period = easingParam[0] );
244         return cc.easeElasticInOut(period).easing(time);
245     },//Elastic_EaesInOut
246 
247     25: cc._easeBackInObj.easing, //Back_EaseIn
248     26: cc._easeBackOutObj.easing, //Back_EaseOut
249     27: cc._easeBackInOutObj.easing, //Back_EaseInOut
250 
251     28: cc._easeBounceInObj.easing, //Bounce_EaseIn
252     29: cc._easeBounceOutObj.easing, //Bounce_EaseOut
253     30: cc._easeBounceInOutObj.easing //Bounce_EaseInOut
254 };
255 
256 /**
257  * Visible frame
258  * To control the display state
259  * @class
260  * @extend ccs.Frame
261  */
262 ccs.VisibleFrame = ccs.Frame.extend({
263 
264     _visible: true,
265 
266     ctor: function(){
267         ccs.Frame.prototype.ctor.call(this);
268         this._visible = true;
269     },
270 
271     /**
272      * the execution of the callback
273      * @param {ccs.Frame} nextFrame
274      */
275     onEnter: function(nextFrame){
276         if(this._node)
277             this._node.setVisible(this._visible);
278     },
279 
280     /**
281      * to copy object with deep copy.
282      * returns a clone of action.
283      * @return {ccs.VisibleFrame}
284      */
285     clone: function(){
286         var frame = new ccs.VisibleFrame();
287         frame.setVisible(this._visible);
288 
289         frame._cloneProperty(this);
290 
291         return frame;
292     },
293 
294     /**
295      * Set display state
296      * @param {Boolean} visible
297      */
298     setVisible: function(visible){
299         this._visible = visible;
300     },
301 
302     /**
303      * Get the display state
304      * @returns {Boolean}
305      */
306     isVisible: function(){
307         return this._visible;
308     }
309 
310 });
311 
312 /**
313  * Create the visible frame
314  *
315  * @deprecated v3.0, please use new ccs.VisibleFrame() instead.
316  * @returns {ccs.VisibleFrame}
317  */
318 ccs.VisibleFrame.create = function(){
319     return new ccs.VisibleFrame();
320 };
321 
322 /**
323  * Texture frame
324  * @class
325  * @extend ccs.Frame
326  */
327 ccs.TextureFrame = ccs.Frame.extend({
328 
329     _sprite: null,
330     _textureName: null,
331 
332     ctor: function(){
333         ccs.Frame.prototype.ctor.call(this);
334 
335         this._textureName = "";
336     },
337 
338     /**
339      * Set the node element to draw texture
340      * @param {cc.Node} node
341      */
342     setNode: function(node){
343         ccs.Frame.prototype.setNode.call(this, node);
344         this._sprite = node;
345     },
346 
347     /**
348      * the execution of the callback
349      * @param {ccs.Frame} nextFrame
350      */
351     onEnter: function(nextFrame){
352         if(this._sprite){
353             var spriteBlendFunc = this._sprite.getBlendFunc();
354             var spriteFrame = cc.spriteFrameCache._spriteFrames[this._textureName];
355             if(spriteFrame != null)
356                 this._sprite.setSpriteFrame(spriteFrame);
357             else
358                 this._sprite.setTexture(this._textureName);
359 
360             if(this._sprite.getBlendFunc() !== spriteBlendFunc)
361                 this._sprite.setBlendFunc(spriteBlendFunc);
362         }
363 
364     },
365 
366     /**
367      * to copy object with deep copy.
368      * returns a clone of action.
369      * @return {ccs.TextureFrame}
370      */
371     clone: function(){
372         var frame = new ccs.TextureFrame();
373         frame.setTextureName(this._textureName);
374         frame._cloneProperty(this);
375         return frame;
376     },
377 
378     /**
379      * Set the texture name
380      * @param {string} textureName
381      */
382     setTextureName: function(textureName){
383         this._textureName = textureName;
384     },
385 
386     /**
387      * Gets the Texture name
388      * @returns {null}
389      */
390     getTextureName: function(){
391         return this._textureName;
392     }
393 
394 });
395 
396 /**
397  * Create the Texture frame
398  *
399  * @deprecated v3.0, please use new ccs.TextureFrame() instead.
400  * @returns {ccs.TextureFrame}
401  */
402 ccs.TextureFrame.create = function(){
403     return new ccs.TextureFrame();
404 };
405 
406 /**
407  * Rotation Frame
408  * @class
409  * @extend ccs.Frame
410  */
411 ccs.RotationFrame = ccs.Frame.extend({
412 
413     _rotation: null,
414     _betwennRotation: null,
415 
416     ctor: function(){
417         ccs.Frame.prototype.ctor.call(this);
418         this._rotation = 0;
419     },
420 
421     /**
422      * the execution of the callback
423      * @param {ccs.Frame} nextFrame
424      */
425     onEnter: function(nextFrame){
426         if(!this._node)
427             return;
428         this._node.setRotation(this._rotation);
429 
430         if(this._tween){
431             this._betwennRotation = nextFrame._rotation - this._rotation;
432         }
433     },
434 
435     /**
436      * Each frame logic
437      * @param {number} percent
438      */
439     _onApply: function(percent){
440         if (this._betwennRotation !== 0){
441             var rotation = this._rotation + percent * this._betwennRotation;
442             this._node.setRotation(rotation);
443         }
444     },
445 
446     /**
447      * to copy object with deep copy.
448      * returns a clone of action.
449      * @return {ccs.RotationFrame}
450      */
451     clone: function(){
452         var frame = new ccs.RotationFrame();
453         frame.setRotation(this._rotation);
454 
455         frame._cloneProperty(this);
456 
457         return frame;
458     },
459 
460     /**
461      * Set the rotation
462      * @param {Number} rotation
463      */
464     setRotation: function(rotation){
465         this._rotation = rotation;
466     },
467 
468     /**
469      * Gets the rotation
470      * @returns {Number}
471      */
472     getRotation: function(){
473         return this._rotation;
474     }
475 
476 });
477 
478 /**
479  * Create the Rotation frame
480  *
481  * @deprecated v3.0, please use new ccs.RotationFrame() instead.
482  * @returns {ccs.RotationFrame}
483  */
484 ccs.RotationFrame.create = function(){
485     return new ccs.RotationFrame();
486 };
487 
488 /**
489  * Skew frame
490  * @class
491  * @extend ccs.Frame
492  */
493 ccs.SkewFrame = ccs.Frame.extend({
494 
495     _skewX: null,
496     _skewY: null,
497     _betweenSkewX: null,
498     _betweenSkewY: null,
499 
500     ctor: function(){
501         ccs.Frame.prototype.ctor.call(this);
502         this._skewX = 0;
503         this._skewY = 0;
504     },
505 
506     /**
507      * the execution of the callback
508      * @param {ccs.Frame} nextFrame
509      */
510     onEnter: function(nextFrame){
511         if(!this._node)
512             return;
513         this._node.setSkewX(this._skewX);
514         this._node.setSkewY(this._skewY);
515 
516         if(this._tween){
517             this._betweenSkewX = nextFrame._skewX - this._skewX;
518             this._betweenSkewY = nextFrame._skewY - this._skewY;
519         }
520 
521     },
522 
523     /**
524      * Each frame logic
525      * @param {number} percent
526      */
527     _onApply: function(percent){
528         if (this._betweenSkewX !== 0 || this._betweenSkewY !== 0)
529         {
530             var skewx = this._skewX + percent * this._betweenSkewX;
531             var skewy = this._skewY + percent * this._betweenSkewY;
532 
533             this._node.setSkewX(skewx);
534             this._node.setSkewY(skewy);
535         }
536     },
537 
538     /**
539      * to copy object with deep copy.
540      * returns a clone of action.
541      * @return {ccs.SkewFrame}
542      */
543     clone: function(){
544         var frame = new ccs.SkewFrame();
545         frame.setSkewX(this._skewX);
546         frame.setSkewY(this._skewY);
547 
548         frame._cloneProperty(this);
549 
550         return frame;
551     },
552 
553     /**
554      * Set the skew x
555      * @param {Number} skewx
556      */
557     setSkewX: function(skewx){
558         this._skewX = skewx;
559     },
560 
561     /**
562      * Gets the skew x
563      * @returns {Number}
564      */
565     getSkewX: function(){
566         return this._skewX;
567     },
568 
569     /**
570      * Set the skew y
571      * @param {Number} skewy
572      */
573     setSkewY: function(skewy){
574         this._skewY = skewy;
575     },
576 
577     /**
578      * Gets the skew y
579      * @returns {Number}
580      */
581     getSkewY: function(){
582         return this._skewY;
583     }
584 
585 });
586 
587 /**
588  * Create the Skew frame
589  *
590  * @deprecated v3.0, please use new ccs.SkewFrame() instead.
591  * @returns {ccs.SkewFrame}
592  */
593 ccs.SkewFrame.create = function(){
594     return new ccs.SkewFrame();
595 };
596 
597 /**
598  * Rotation skew frame
599  * @class
600  * @extend ccs.SkewFrame
601  */
602 ccs.RotationSkewFrame = ccs.SkewFrame.extend({
603 
604     /**
605      * the execution of the callback
606      * @param {ccs.Frame} nextFrame
607      */
608     onEnter: function(nextFrame){
609         if(!this._node)
610             return;
611         this._node.setRotationX(this._skewX);
612         this._node.setRotationY(this._skewY);
613 
614         if (this._tween){
615             this._betweenSkewX = nextFrame._skewX - this._skewX;
616             this._betweenSkewY = nextFrame._skewY - this._skewY;
617         }
618 
619     },
620 
621     /**
622      * Each frame logic
623      * @param {number} percent
624      */
625     _onApply: function(percent){
626         if (this._node && (this._betweenSkewX !== 0 || this._betweenSkewY !== 0)){
627             var skewx = this._skewX + percent * this._betweenSkewX;
628             var skewy = this._skewY + percent * this._betweenSkewY;
629 
630             this._node.setRotationX(skewx);
631             this._node.setRotationY(skewy);
632         }
633 
634     },
635 
636     /**
637      * to copy object with deep copy.
638      * returns a clone of action.
639      * @return {ccs.RotationSkewFrame}
640      */
641     clone: function(){
642         var frame = new ccs.RotationSkewFrame();
643         frame.setSkewX(this._skewX);
644         frame.setSkewY(this._skewY);
645 
646         frame._cloneProperty(this);
647 
648         return frame;
649 
650     }
651 
652 });
653 
654 /**
655  * Create the RotationSkew frame
656  *
657  * @deprecated v3.0, please use new ccs.RotationSkewFrame() instead.
658  * @returns {ccs.RotationSkewFrame}
659  */
660 ccs.RotationSkewFrame.create = function(){
661     return new ccs.RotationSkewFrame();
662 };
663 
664 /**
665  * Position frame
666  * @class
667  * @extend ccs.Frame
668  */
669 ccs.PositionFrame = ccs.Frame.extend({
670 
671     _position: null,
672     _betweenX: null,
673     _betweenY: null,
674 
675     ctor: function(){
676         ccs.Frame.prototype.ctor.call(this);
677         this._position = cc.p(0, 0);
678     },
679 
680     /**
681      * the execution of the callback
682      * @param {ccs.Frame} nextFrame
683      */
684     onEnter: function(nextFrame){
685         if(!this._node)
686             return;
687 
688         this._node.setPosition(this._position);
689 
690         if(this._tween){
691             this._betweenX = nextFrame._position.x - this._position.x;
692             this._betweenY = nextFrame._position.y - this._position.y;
693         }
694     },
695 
696     /**
697      * Each frame logic
698      * @param {number} percent
699      */
700     _onApply: function(percent){
701         if (this._node && (this._betweenX !== 0 || this._betweenY !== 0)){
702             var p = cc.p(0, 0);
703             p.x = this._position.x + this._betweenX * percent;
704             p.y = this._position.y + this._betweenY * percent;
705 
706             this._node.setPosition(p);
707         }
708     },
709 
710     /**
711      * to copy object with deep copy.
712      * returns a clone of action.
713      * @return {ccs.PositionFrame}
714      */
715     clone: function(){
716         var frame = new ccs.PositionFrame();
717         frame.setPosition(this._position);
718 
719         frame._cloneProperty(this);
720 
721         return frame;
722     },
723 
724     /**
725      * Set the position
726      * @param {cc.p} position
727      */
728     setPosition: function(position){
729         this._position = position;
730     },
731 
732     /**
733      * gets the position
734      * @returns {cc.p}
735      */
736     getPosition: function(){
737         return this._position;
738     },
739 
740     /**
741      * Set the position x
742      * @param {Number} x
743      */
744     setX: function(x){
745         this._position.x = x;
746     },
747 
748     /**
749      * Gets the position x
750      * @returns {Number}
751      */
752     getX: function(){
753         return this._position.x;
754     },
755 
756     /**
757      * Set the position y
758      * @param {Number} y
759      */
760     setY: function(y){
761         this._position.y = y;
762     },
763 
764     /**
765      * Gets the position y
766      * @returns {Number}
767      */
768     getY: function(){
769         return this._position.y;
770     }
771 
772 });
773 
774 /**
775  * Create the Position frame
776  *
777  * @deprecated v3.0, please use new ccs.PositionFrame() instead.
778  * @returns {ccs.PositionFrame}
779  */
780 ccs.PositionFrame.create = function(){
781     return new ccs.PositionFrame();
782 };
783 
784 /**
785  * Scale frame
786  * @class
787  * @xtend ccs.Frame
788  */
789 ccs.ScaleFrame = ccs.Frame.extend({
790 
791     _scaleX: null,
792     _scaleY: null,
793     _betweenScaleX: null,
794     _betweenScaleY: null,
795 
796     ctor: function(){
797         ccs.Frame.prototype.ctor.call(this);
798         this._scaleX = 1;
799         this._scaleY = 1;
800     },
801 
802     /**
803      * the execution of the callback
804      * @param {ccs.Frame} nextFrame
805      */
806     onEnter: function(nextFrame){
807         if(!this._node)
808             return;
809         this._node.setScaleX(this._scaleX);
810         this._node.setScaleY(this._scaleY);
811 
812         if(this._tween){
813             this._betweenScaleX = nextFrame._scaleX - this._scaleX;
814             this._betweenScaleY = nextFrame._scaleY - this._scaleY;
815         }
816 
817     },
818 
819     /**
820      * Each frame logic
821      * @param {number} percent
822      */
823     _onApply: function(percent){
824         if (this._node && (this._betweenScaleX !== 0 || this._betweenScaleY !== 0)){
825             var scaleX = this._scaleX + this._betweenScaleX * percent;
826             var scaleY = this._scaleY + this._betweenScaleY * percent;
827 
828             this._node.setScaleX(scaleX);
829             this._node.setScaleY(scaleY);
830         }
831     },
832 
833     /**
834      * to copy object with deep copy.
835      * returns a clone of action.
836      * @return {ccs.ScaleFrame}
837      */
838     clone: function(){
839         var frame = new ccs.ScaleFrame();
840         frame.setScaleX(this._scaleX);
841         frame.setScaleY(this._scaleY);
842 
843         frame._cloneProperty(this);
844 
845         return frame;
846 
847     },
848 
849     /**
850      * Set the scale
851      * @param {Number} scale
852      */
853     setScale: function(scale){
854         this._scaleX = scale;
855         this._scaleY = scale;
856     },
857 
858     /**
859      * Set the scale x
860      * @param {Number} scaleX
861      */
862     setScaleX: function(scaleX){
863         this._scaleX = scaleX;
864     },
865 
866     /**
867      * Gets the scale x
868      * @returns {Number}
869      */
870     getScaleX: function(){
871         return this._scaleX;
872     },
873 
874     /**
875      * Set the scale y
876      * @param {Number} scaleY
877      */
878     setScaleY: function(scaleY){
879         this._scaleY = scaleY;
880     },
881 
882     /**
883      * Gets the scale y
884      * @returns {Number}
885      */
886     getScaleY: function(){
887         return this._scaleY;
888     }
889 
890 });
891 
892 /**
893  * Create the Scale frame
894  *
895  * @deprecated v3.0, please use new ccs.ScaleFrame() instead.
896  * @returns {ccs.ScaleFrame}
897  */
898 ccs.ScaleFrame.create = function(){
899     return new ccs.ScaleFrame();
900 };
901 
902 /**
903  * AnchorPoint frame
904  * @class
905  * @extend ccs.Frame
906  */
907 ccs.AnchorPointFrame = ccs.Frame.extend({
908 
909     _anchorPoint: null,
910 
911     ctor: function(){
912         ccs.Frame.prototype.ctor.call(this);
913         this._anchorPoint = cc.p(0, 0);
914     },
915 
916     /**
917      * the execution of the callback
918      * @param {ccs.Frame} nextFrame
919      */
920     onEnter: function(nextFrame){
921         if(this._node)
922             this._node.setAnchorPoint(this._anchorPoint);
923     },
924 
925     /**
926      * to copy object with deep copy.
927      * returns a clone of action.
928      * @return {ccs.AnchorPointFrame}
929      */
930     clone: function(){
931         var frame = new ccs.AnchorPointFrame();
932         frame.setAnchorPoint(this._anchorPoint);
933 
934         frame._cloneProperty(this);
935 
936         return frame;
937     },
938 
939     /**
940      * Set the anchor point
941      * @param {cc.p} point
942      */
943     setAnchorPoint: function(point){
944         this._anchorPoint = point;
945     },
946 
947     /**
948      * Gets the anchor point
949      * @returns {cc.p}
950      */
951     getAnchorPoint: function(){
952         return this._anchorPoint;
953     }
954 
955 });
956 
957 /**
958  * Create the AnchorPoint frame
959  *
960  * @deprecated v3.0, please use new ccs.AnchorPointFrame() instead.
961  * @returns {ccs.AnchorPointFrame}
962  */
963 ccs.AnchorPointFrame.create = function(){
964     return new ccs.AnchorPointFrame();
965 };
966 
967 /**
968  * Static param
969  * @namespace
970  */
971 ccs.InnerActionType = {
972     LoopAction : 0,
973     NoLoopAction : 1,
974     SingleFrame : 2
975 };
976 
977 /**
978  * Inner action frame
979  * @class
980  * @extend ccs.Frame
981  */
982 ccs.InnerActionFrame = ccs.Frame.extend({
983 
984     _innerActionType: null,
985     _startFrameIndex: null,
986 
987     _endFrameIndex:0,
988     _singleFrameIndex: 0,
989     _enterWithName: null,
990     _animationName: "",
991 
992     ctor: function(){
993         ccs.Frame.prototype.ctor.call(this);
994 
995         this._enterWithName = false;
996         this._innerActionType = ccs.InnerActionType.LoopAction;
997         this._startFrameIndex = 0;
998     },
999 
1000     /**
1001      * the execution of the callback
1002      * @param {ccs.Frame} nextFrame
1003      */
1004     onEnter: function(nextFrame){
1005         if(!this._node)  return;
1006         var innerActiontimeline = this._node.getActionByTag(this._node.getTag());
1007         if(!innerActiontimeline) return;
1008         if (ccs.InnerActionType.SingleFrame === this._innerActionType){
1009             innerActiontimeline.gotoFrameAndPause(this._singleFrameIndex);
1010             return;
1011         }
1012 
1013         var innerStart = this._startFrameIndex;
1014         var innerEnd = this._endFrameIndex;
1015         if (this._enterWithName){
1016             if (this._animationName === "-- ALL --"){
1017                 innerStart = 0;
1018                 innerEnd = innerActiontimeline.getDuration();
1019             } else if(innerActiontimeline.isAnimationInfoExists(this._animationName)) {
1020                 var info = innerActiontimeline.getAnimationInfo(this._animationName);
1021                 innerStart = info.startIndex;
1022                 innerEnd = info.endIndex;
1023             }else{
1024                 cc.log("Animation %s not exists!", this._animationName);
1025             }
1026         }
1027 
1028         var duration = this._timeline.getActionTimeline().getDuration();
1029         var odddiff = duration - this._frameIndex - innerEnd + innerStart;
1030         if (odddiff < 0){
1031             innerEnd += odddiff;
1032         }
1033 
1034         if (ccs.InnerActionType.NoLoopAction === this._innerActionType){
1035             innerActiontimeline.gotoFrameAndPlay(innerStart, innerEnd, false);
1036         }else if (ccs.InnerActionType.LoopAction === this._innerActionType){
1037             innerActiontimeline.gotoFrameAndPlay(innerStart, innerEnd, true);
1038         }
1039     },
1040 
1041     setAnimationName: function(animationName){
1042         this._animationName = animationName;
1043     },
1044 
1045     setSingleFrameIndex: function(frameIndex){
1046         this._singleFrameIndex = frameIndex;
1047     },
1048 
1049     getSingleFrameIndex: function(){
1050         return this._startFrameIndex;
1051     },
1052 
1053     setEnterWithName: function(isEnterWithName){
1054         this._enterWithName = isEnterWithName;
1055     },
1056 
1057     getEnterWithName: function(){
1058         return this._enterWithName;
1059     },
1060 
1061     /**
1062      * to copy object with deep copy.
1063      * returns a clone of action.
1064      * @return {ccs.InnerActionFrame}
1065      */
1066     clone: function(){
1067         var frame = new ccs.InnerActionFrame();
1068         frame.setInnerActionType(this._innerActionType);
1069         frame.setStartFrameIndex(this._startFrameIndex);
1070         frame.setEnterWithName(this._enterWithName);
1071         frame.setAnimationName(this._animationName);
1072         frame.setSingleFrameIndex(this._singleFrameIndex);
1073 
1074         frame._cloneProperty(this);
1075 
1076         return frame;
1077 
1078     },
1079 
1080     /**
1081      * Set the inner action type
1082      * @param {ccs.InnerActionType} type
1083      */
1084     setInnerActionType: function(type){
1085         this._innerActionType = type;
1086     },
1087 
1088     /**
1089      * Gets the inner action type
1090      * @returns {ccs.InnerActionType}
1091      */
1092     getInnerActionType: function(){
1093         return this._innerActionType;
1094     },
1095 
1096     /**
1097      * Set the start frame index
1098      * @param {Number} frameIndex
1099      */
1100     setStartFrameIndex: function(frameIndex){
1101         this._startFrameIndex = frameIndex;
1102     },
1103 
1104     /**
1105      * Get the start frame index
1106      * @returns {Number}
1107      */
1108     getStartFrameIndex: function(){
1109         return this._startFrameIndex;
1110     }
1111 
1112 });
1113 
1114 /**
1115  * Create the InnerAction frame
1116  *
1117  * @deprecated v3.0, please use new ccs.InnerActionFrame() instead.
1118  * @returns {ccs.InnerActionFrame}
1119  */
1120 ccs.InnerActionFrame.create = function(){
1121     return new ccs.InnerActionFrame();
1122 };
1123 
1124 /**
1125  * Color frame
1126  * @class
1127  * @extend ccs.Frame
1128  */
1129 ccs.ColorFrame = ccs.Frame.extend({
1130 
1131     _alpha: null,
1132     _color: null,
1133 
1134     _betweenAlpha: null,
1135     _betweenRed: null,
1136     _betweenGreen: null,
1137     _betweenBlue: null,
1138 
1139     ctor: function(){
1140         ccs.Frame.prototype.ctor.call(this);
1141         this._color = cc.color(255, 255, 255);
1142     },
1143 
1144     /**
1145      * the execution of the callback
1146      * @param {ccs.ColorFrame} nextFrame
1147      */
1148     onEnter: function(nextFrame){
1149         if(!this._node)
1150             return;
1151         this._node.setColor(this._color);
1152         if(this._tween){
1153             var color = nextFrame._color;
1154             this._betweenRed   = color.r - this._color.r;
1155             this._betweenGreen = color.g - this._color.g;
1156             this._betweenBlue  = color.b - this._color.b;
1157         }
1158 
1159     },
1160 
1161     /**
1162      * Each frame logic
1163      * @param {number} percent
1164      */
1165     _onApply: function(percent){
1166         if (this._node && this._tween && (this._betweenAlpha !== 0 || this._betweenRed !== 0 || this._betweenGreen !== 0 || this._betweenBlue !== 0)){
1167 
1168             var color = cc.color(255, 255, 255);
1169             color.r = this._color.r + this._betweenRed   * percent;
1170             color.g = this._color.g + this._betweenGreen * percent;
1171             color.b = this._color.b + this._betweenBlue  * percent;
1172 
1173             this._node.setColor(color);
1174             if(this._alpha !== null){
1175                 var alpha = this._alpha + this._betweenAlpha * percent;
1176                 this._node.setOpacity(alpha);
1177             }
1178 
1179         }
1180     },
1181 
1182     /**
1183      * to copy object with deep copy.
1184      * returns a clone of action.
1185      * @return {ccs.ColorFrame}
1186      */
1187     clone: function(){
1188         var frame = new ccs.ColorFrame();
1189         frame.setColor(this._color);
1190         frame._cloneProperty(this);
1191         return frame;
1192     },
1193 
1194     /**
1195      * Set the color
1196      * @param {cc.color} color
1197      */
1198     setColor: function(color){
1199         this._color = color;
1200     },
1201 
1202     /**
1203      * Gets the color
1204      * @returns {cc.color}
1205      */
1206     getColor: function(){
1207         return this._color;
1208     }
1209 
1210 });
1211 
1212 /**
1213  * Create the Color frame
1214  *
1215  * @deprecated v3.0, please use new ccs.ColorFrame() instead.
1216  * @returns {ccs.ColorFrame}
1217  */
1218 ccs.ColorFrame.create = function(){
1219     return new ccs.ColorFrame();
1220 };
1221 
1222 /**
1223  * Alpha frame
1224  * @class
1225  * @extend ccs.Frame
1226  */
1227 ccs.AlphaFrame = ccs.Frame.extend({
1228 
1229     _alpha: null,
1230     _betweenAlpha: null,
1231 
1232     ctor: function(){
1233         ccs.Frame.prototype.ctor.call(this);
1234         this._alpha = 255;
1235     },
1236 
1237     onEnter: function(nextFrame){
1238         if(!this._node)
1239             return;
1240         this._node.setOpacity(this._alpha);
1241         if(this._tween){
1242             this._betweenAlpha = nextFrame._alpha - this._alpha;
1243         }
1244     },
1245 
1246     _onApply: function(percent){
1247         if(!this._node)
1248             return;
1249         var alpha = this._alpha + this._betweenAlpha * percent;
1250         this._node.setOpacity(alpha);
1251     },
1252 
1253     /**
1254      * Set the alpha
1255      * @param {Number} alpha
1256      */
1257     setAlpha: function(alpha){
1258         this._alpha = alpha;
1259     },
1260 
1261     /**
1262      * Gets the alpha
1263      * @returns {Number}
1264      */
1265     getAlpha: function(){
1266         return this._alpha;
1267     },
1268 
1269     clone: function(){
1270         var frame = new ccs.AlphaFrame();
1271         frame.setAlpha(this._alpha);
1272         frame._cloneProperty(this);
1273         return frame;
1274     }
1275 });
1276 
1277 /**
1278  * Event frame
1279  * @class
1280  * @extend ccs.Frame
1281  */
1282 ccs.EventFrame = ccs.Frame.extend({
1283 
1284     _event: null,
1285 
1286     ctor: function(){
1287         ccs.Frame.prototype.ctor.call(this);
1288         this._event = "";
1289         this._enterWhenPassed = true;
1290     },
1291 
1292     /**
1293      * the execution of the callback
1294      * @param {ccs.Frame} nextFrame
1295      */
1296     onEnter: function(nextFrame){
1297         this._emitEvent();
1298     },
1299 
1300     /**
1301      * to copy object with deep copy.
1302      * returns a clone of action.
1303      * @return {ccs.EventFrame}
1304      */
1305     clone: function(){
1306         var frame = new ccs.EventFrame();
1307         frame.setEvent(this._event);
1308 
1309         frame._cloneProperty(this);
1310 
1311         return frame;
1312     },
1313 
1314     /**
1315      * Set the event
1316      * @param event
1317      */
1318     setEvent: function(event){
1319         this._event = event;
1320     },
1321 
1322     /**
1323      * Gets the event
1324      * @returns {null}
1325      */
1326     getEvent: function(){
1327         return this._event;
1328     }
1329 
1330 });
1331 
1332 /**
1333  * Create the Event frame
1334  *
1335  * @deprecated v3.0, please use new ccs.EventFrame() instead.
1336  * @returns {ccs.EventFrame}
1337  */
1338 ccs.EventFrame.create = function(){
1339     return new ccs.EventFrame();
1340 };
1341 
1342 /**
1343  * zOrder frame
1344  * @class
1345  * @extend ccs.Frame
1346  */
1347 ccs.ZOrderFrame = ccs.Frame.extend({
1348 
1349     _zorder: 0,
1350 
1351     /**
1352      * the execution of the callback
1353      * @param {ccs.Frame} nextFrame
1354      */
1355     onEnter: function(nextFrame){
1356         if(this._node)
1357             this._node.setLocalZOrder(this._zorder);
1358     },
1359 
1360     /**
1361      * to copy object with deep copy.
1362      * returns a clone of action.
1363      * @return {ccs.ZOrderFrame}
1364      */
1365     clone: function(){
1366         var frame = new ccs.ZOrderFrame();
1367         frame.setZOrder(this._zorder);
1368 
1369         frame._cloneProperty(this);
1370 
1371         return frame;
1372     },
1373 
1374     /**
1375      * Set the zOrder
1376      * @param {Number} zorder
1377      */
1378     setZOrder: function(zorder){
1379         this._zorder = zorder;
1380     },
1381 
1382     /**
1383      * Gets the zOrder
1384      * @returns {Number}
1385      */
1386     getZOrder: function(){
1387         return this._zorder;
1388     }
1389 
1390 });
1391 
1392 /**
1393  * Create the ZOrder frame
1394  *
1395  * @deprecated v3.0, please use new ccs.ZOrderFrame() instead.
1396  * @returns {ccs.ZOrderFrame}
1397  */
1398 ccs.ZOrderFrame.create = function(){
1399     return new ccs.ZOrderFrame();
1400 };
1401 
1402 ccs.BlendFuncFrame = ccs.Frame.extend({
1403     ctor: function () {
1404         this._super();
1405         this._blendFunc = null;
1406     },
1407 
1408     onEnter: function(nextFrame, currentFrameIndex){
1409         if(this._node && this._blendFunc)
1410             this._node.setBlendFunc(this._blendFunc);
1411     },
1412 
1413     clone: function(){
1414         var frame = new ccs.BlendFuncFrame();
1415         frame.setBlendFunc(this._blendFunc);
1416         frame._cloneProperty(this);
1417         return frame;
1418     },
1419 
1420     setBlendFunc: function(blendFunc){
1421         if (blendFunc && blendFunc.src && blendFunc.dst)
1422             this._blendFunc = blendFunc;
1423     },
1424 
1425     getBlendFunc: function(){
1426         return this._blendFunc;
1427     }
1428 });
1429 
1430 ccs.BlendFuncFrame.create = function(){
1431     return new ccs.BlendFuncFrame();
1432 };