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  * @class
 29  * @extends cc.Class
 30  */
 31 cc.ActionTweenDelegate = cc.Class.extend(/** @lends cc.ActionTweenDelegate */{
 32 
 33     /**
 34      * @function
 35      * @param value
 36      * @param key
 37      */
 38     updateTweenAction:function(value, key){
 39 
 40     }
 41 });
 42 
 43 /**
 44  * cc.ActionTween
 45  * cc.ActionTween is an action that lets you update any property of an object.
 46  *
 47  * @class
 48  * @extends cc.ActionInterval
 49  * @example
 50  * //For example, if you want to modify the "width" property of a target from 200 to 300 in 2 seconds, then:
 51  *  var modifyWidth = cc.ActionTween.create(2,"width",200,300)
 52  *  target.runAction(modifyWidth);
 53  *
 54  * //Another example: cc.ScaleTo action could be rewriten using cc.PropertyAction:
 55  * // scaleA and scaleB are equivalents
 56  * var scaleA = cc.ScaleTo.create(2,3);
 57  * var scaleB = cc.ActionTween.create(2,"scale",1,3);
 58  */
 59 cc.ActionTween = cc.ActionInterval.extend(/** @lends cc.ActionTween */{
 60     key:"",
 61     from:0,
 62     to:0,
 63     delta:0,
 64 
 65 	/**
 66 	 * Creates an initializes the action with the property name (key), and the from and to parameters.
 67 	 * Constructor of cc.ActionTween
 68 	 * @param {Number} duration
 69 	 * @param {String} key
 70 	 * @param {Number} from
 71 	 * @param {Number} to
 72 	 */
 73     ctor:function(duration, key, from, to){
 74         cc.ActionInterval.prototype.ctor.call(this);
 75         this.key = "";
 76 
 77 		to !== undefined && this.initWithDuration(duration, key, from, to);
 78     },
 79 
 80     /**
 81      * initializes the action with the property name (key), and the from and to parameters.
 82      * @param {Number} duration
 83      * @param {String} key
 84      * @param {Number} from
 85      * @param {Number} to
 86      * @return {Boolean}
 87      */
 88     initWithDuration:function (duration, key, from, to) {
 89         if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
 90             this.key = key;
 91             this.to = to;
 92             this.from = from;
 93             return true;
 94         }
 95         return false;
 96     },
 97     /**
 98      * @param {cc.Node} target
 99      */
100     startWithTarget:function (target) {
101         if(!target || !target.updateTweenAction)
102             throw "cc.ActionTween.startWithTarget(): target must be non-null, and target must implement updateTweenAction function";
103         cc.ActionInterval.prototype.startWithTarget.call(this, target);
104         this.delta = this.to - this.from;
105     },
106     /**
107      * @param {Number} dt
108      */
109     update:function (dt) {
110         this.target.updateTweenAction(this.to - this.delta * (1 - dt), this.key);
111     },
112     /**
113      * @return {cc.ActionTween}
114      */
115     reverse:function () {
116         return cc.ActionTween.create(this.duration, this.key, this.to, this.from);
117     },
118 
119     clone:function(){
120         var action = new cc.ActionTween();
121         action.initWithDuration(this._duration, this.key, this.from, this.to);
122         return action;
123     }
124 });
125 
126 /**
127  * Creates an initializes the action with the property name (key), and the from and to parameters.
128  * @param {Number} duration
129  * @param {String} key
130  * @param {Number} from
131  * @param {Number} to
132  * @return {cc.ActionTween}
133  */
134 cc.ActionTween.create = function (duration, key, from, to) {
135     var ret = new cc.ActionTween();
136     if (ret.initWithDuration(duration, key, from, to))
137         return ret;
138     return null;
139 };
140 
141 cc.action = cc.Action.create;
142 cc.speed = cc.Speed.create;
143 cc.follow = cc.Follow.create;
144 cc.orbitCamera = cc.OrbitCamera.create;
145 cc.cardinalSplineTo = cc.CardinalSplineTo.create;
146 cc.cardinalSplineBy = cc.CardinalSplineBy.create;
147 cc.catmullRomTo = cc.CatmullRomTo.create;
148 cc.catmullRomBy = cc.CatmullRomBy.create;
149 cc.show = cc.Show.create;
150 cc.hide = cc.Hide.create;
151 cc.toggleVisibility = cc.ToggleVisibility.create;
152 cc.removeSelf = cc.RemoveSelf.create;
153 cc.flipX = cc.FlipX.create;
154 cc.flipY = cc.FlipY.create;
155 cc.place = cc.Place.create;
156 cc.callFunc = cc.CallFunc.create;
157 cc.actionInterval = cc.ActionInterval.create;
158 cc.sequence = cc.Sequence.create;
159 cc.repeat = cc.Repeat.create;
160 cc.repeatForever = cc.RepeatForever.create;
161 cc.spawn = cc.Spawn.create;
162 cc.rotateTo = cc.RotateTo.create;
163 cc.rotateBy = cc.RotateBy.create;
164 cc.moveBy = cc.MoveBy.create;
165 cc.moveTo = cc.MoveTo.create;
166 cc.skewTo = cc.SkewTo.create;
167 cc.skewBy = cc.SkewBy.create;
168 cc.jumpBy = cc.JumpBy.create;
169 cc.jumpTo = cc.JumpTo.create;
170 cc.bezierBy = cc.BezierBy.create;
171 cc.bezierTo = cc.BezierTo.create;
172 cc.scaleTo = cc.ScaleTo.create;
173 cc.scaleBy = cc.ScaleBy.create;
174 cc.blink = cc.Blink.create;
175 cc.fadeTo = cc.FadeTo.create;
176 cc.fadeIn = cc.FadeIn.create;
177 cc.fadeOut = cc.FadeOut.create;
178 cc.tintTo = cc.TintTo.create;
179 cc.tintBy = cc.TintBy.create;
180 cc.delayTime = cc.DelayTime.create;
181 cc.reverseTime = cc.ReverseTime.create;
182 cc.animate = cc.Animate.create;
183 cc.targetedAction = cc.TargetedAction.create;
184 cc.actionTween = cc.ActionTween.create;