1 /****************************************************************************
  2  Copyright (c) 2010-2012 cocos2d-x.org
  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  * Action frame type
 27  * @constant
 28  * @type Object
 29  */
 30 ccs.FrameType = {
 31     move: 0,
 32     scale: 1,
 33     rotate: 2,
 34     tint: 3,
 35     fade: 4,
 36     max: 5
 37 };
 38 
 39 /**
 40  * Base class for ccs.ActionFrame
 41  * @class
 42  * @extends ccs.Class
 43  */
 44 ccs.ActionFrame = ccs.Class.extend(/** @lends ccs.ActionFrame# */{
 45     _frameType: 0,
 46     _easingType: 0,
 47     _frameIndex: 0,
 48     _time: 0,
 49     ctor: function () {
 50         this._frameType = 0;
 51         this._easingType = 0;
 52         this._frameIndex = 0;
 53         this._time = 0;
 54     },
 55 
 56     /**
 57      * Changes the index of action frame
 58      * @param {number} index
 59      */
 60     setFrameIndex: function (index) {
 61         this._frameIndex = index;
 62     },
 63 
 64     /**
 65      * Gets the index of action frame
 66      * @returns {number}
 67      */
 68     getFrameIndex: function () {
 69         return this._frameIndex;
 70     },
 71 
 72     /**
 73      * Changes the time of action frame
 74      * @param {number} fTime
 75      */
 76     setFrameTime: function (time) {
 77         this._time = time;
 78     },
 79 
 80     /**
 81      * Gets the time of action frame
 82      * @returns {number}
 83      */
 84     getFrameTime: function () {
 85         return this._time;
 86     },
 87 
 88     /**
 89      * Changes the type of action frame
 90      * @param {number} frameType
 91      */
 92     setFrameType: function (frameType) {
 93         this._frameType = frameType;
 94     },
 95 
 96     /**
 97      * Gets the type of action frame
 98      * @returns {number}
 99      */
100     getFrameType: function () {
101         return this._frameType;
102     },
103 
104     /**
105      * Changes the easing type.
106      * @param {number} easingType
107      */
108     setEasingType: function (easingType) {
109         this._easingType = easingType;
110     },
111 
112     /**
113      * Gets the easing type.
114      * @returns {number}
115      */
116     getEasingType: function () {
117         return this._easingType;
118     },
119 
120     /**
121      * Gets the action of ActionFrame.
122      * @param {number} duration
123      * @returns {null}
124      */
125     getAction: function (duration) {
126         return null;
127     }
128 });
129 
130 /**
131  * Base class for ccs.ActionMoveFrame
132  * @class
133  * @extends ccs.ActionFrame
134  */
135 ccs.ActionMoveFrame = ccs.ActionFrame.extend({
136     _position: null,
137     ctor: function () {
138         ccs.ActionFrame.prototype.ctor.call(this);
139         this._position = cc.p(0, 0);
140         this._frameType = ccs.FrameType.move;
141     },
142 
143     /**
144      * Changes the move action position.
145      * @param {cc.Point} pos
146      */
147     setPosition: function (pos) {
148         this._position = pos;
149     },
150 
151     /**
152      * Gets the move action position.
153      * @returns {cc.Point}
154      */
155     getPosition: function () {
156         return this._position;
157     },
158 
159     /**
160      * Gets the CCAction of ActionFrame.
161      * @param {number} duration
162      * @returns {cc.MoveTo}
163      */
164     getAction: function (duration) {
165         return cc.MoveTo.create(duration, this._position);
166     }
167 });
168 
169 /**
170  * Base class for ccs.ActionScaleFrame
171  * @class
172  * @extends ccs.ActionFrame
173  */
174 ccs.ActionScaleFrame = ccs.ActionFrame.extend({
175     _scaleX: 1,
176     _scaleY: 1,
177     ctor: function () {
178         ccs.ActionFrame.prototype.ctor.call(this);
179         this._scaleX = 1;
180         this._scaleY = 1;
181         this._frameType = ccs.FrameType.scale;
182     },
183 
184     /**
185      * Changes the scale action scaleX.
186      * @param {number} scaleX
187      */
188     setScaleX: function (scaleX) {
189         this._scaleX = scaleX;
190     },
191 
192     /**
193      * Gets the scale action scaleX.
194      * @returns {number} {number}
195      */
196     getScaleX: function () {
197         return this._scaleX;
198     },
199 
200     /**
201      * Changes the scale action scaleY.
202      * @param {number} scaleY
203      */
204     setScaleY: function (scaleY) {
205         this._scaleY = scaleY;
206     },
207 
208     /**
209      * Gets the scale action scaleY.
210      * @returns {number}
211      */
212     getScaleY: function () {
213         return this._scaleY;
214     },
215 
216     /**
217      * Gets the action of ActionFrame.
218      * @param duration
219      * @returns {cc.ScaleTo}
220      */
221     getAction: function (duration) {
222         return cc.ScaleTo.create(duration, this._scaleX, this._scaleY);
223     }
224 });
225 
226 /**
227  * Base class for ccs.ActionRotationFrame
228  * @class
229  * @extends ccs.ActionFrame
230  */
231 ccs.ActionRotationFrame = ccs.ActionFrame.extend({
232     _rotation: 0,
233     ctor: function () {
234         ccs.ActionFrame.prototype.ctor.call(this);
235         this._rotation = 0;
236         this._frameType = ccs.FrameType.rotate;
237     },
238 
239     /**
240      * Changes rotate action rotation.
241      * @param {number} rotation
242      */
243     setRotation: function (rotation) {
244         this._rotation = rotation;
245     },
246 
247     /**
248      * Gets the rotate action rotation.
249      * @returns {number}
250      */
251     getRotation: function () {
252         return this._rotation;
253     },
254 
255     /**
256      * Gets the CCAction of ActionFrame.
257      * @param {number} duration
258      * @returns {cc.RotateTo}
259      */
260     getAction: function (duration) {
261         return cc.RotateTo.create(duration, this._rotation);
262     }
263 });
264 
265 /**
266  * Base class for ccs.ActionFadeFrame
267  * @class
268  * @extends ccs.ActionFrame
269  */
270 ccs.ActionFadeFrame = ccs.ActionFrame.extend({
271     _opacity: 255,
272     ctor: function () {
273         ccs.ActionFrame.prototype.ctor.call(this);
274         this._opacity = 255;
275         this._frameType = ccs.FrameType.fade;
276     },
277 
278     /**
279      * Changes the fade action opacity.
280      * @param {number} opacity
281      */
282     setOpacity: function (opacity) {
283         this._opacity = opacity;
284     },
285 
286     /**
287      * Gets the fade action opacity.
288      * @returns {number}
289      */
290     getOpacity: function () {
291         return this._opacity;
292     },
293 
294     /**
295      * Gets the CCAction of ActionFrame.
296      * @param duration
297      * @returns {cc.FadeTo}
298      */
299     getAction: function (duration) {
300         return cc.FadeTo.create(duration, this._opacity);
301     }
302 });
303 
304 /**
305  * Base class for ccs.ActionTintFrame
306  * @class
307  * @extends ccs.ActionFrame
308  */
309 ccs.ActionTintFrame = ccs.ActionFrame.extend({
310     _color: 255,
311     ctor: function () {
312         ccs.ActionFrame.prototype.ctor.call(this);
313         this._color = 255;
314         this._frameType = ccs.FrameType.tint;
315     },
316 
317     /**
318      * Changes the tint action color.
319      * @param {number} color
320      */
321     setColor: function (color) {
322         this._color = color;
323     },
324 
325     /**
326      * Gets the tint action color.
327      * @returns {number}
328      */
329     getColor: function () {
330         return this._color;
331     },
332 
333     /**
334      * Gets the action of ActionFrame.
335      * @param duration
336      * @returns {cc.TintTo}
337      */
338     getAction: function (duration) {
339         return cc.TintTo.create(duration, this._color.r, this._color.g, this._color.b);
340     }
341 });