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 //Action frame type 26 /** 27 * @ignore 28 */ 29 ccs.FRAME_TYPE_MOVE = 0; 30 ccs.FRAME_TYPE_SCALE = 1; 31 ccs.FRAME_TYPE_ROTATE = 2; 32 ccs.FRAME_TYPE_TINT = 3; 33 ccs.FRAME_TYPE_FADE = 4; 34 ccs.FRAME_TYPE_MAX = 5; 35 36 /** 37 * Base class for ccs.ActionFrame 38 * @class 39 * @extends ccs.Class 40 */ 41 ccs.ActionFrame = ccs.Class.extend(/** @lends ccs.ActionFrame# */{ 42 frameType: 0, 43 easingType: 0, 44 frameIndex: 0, 45 time: 0, 46 ctor: function () { 47 this.frameType = 0; 48 this.easingType = 0; 49 this.frameIndex = 0; 50 this.time = 0; 51 }, 52 53 /** 54 * Gets the action of ActionFrame. 55 * @param {number} duration 56 * @returns {null} 57 */ 58 getAction: function (duration) { 59 return null; 60 } 61 }); 62 63 /** 64 * Base class for ccs.ActionMoveFrame 65 * @class 66 * @extends ccs.ActionFrame 67 */ 68 ccs.ActionMoveFrame = ccs.ActionFrame.extend(/** @lends ccs.ActionMoveFrame# */{ 69 _position: null, 70 ctor: function () { 71 ccs.ActionFrame.prototype.ctor.call(this); 72 this._position = cc.p(0, 0); 73 this.frameType = ccs.FRAME_TYPE_MOVE; 74 }, 75 76 /** 77 * Changes the move action position. 78 * @param {cc.Point|Number} pos 79 * @param {Number} y 80 */ 81 setPosition: function (pos, y) { 82 if (y === undefined) { 83 this._position.x = pos.x; 84 this._position.y = pos.y; 85 } else { 86 this._position.x = pos; 87 this._position.y = y; 88 } 89 }, 90 91 /** 92 * Gets the move action position. 93 * @returns {cc.Point} 94 */ 95 getPosition: function () { 96 return this._position; 97 }, 98 99 /** 100 * Gets the CCAction of ActionFrame. 101 * @param {number} duration 102 * @returns {cc.MoveTo} 103 */ 104 getAction: function (duration) { 105 return cc.MoveTo.create(duration, this._position); 106 } 107 }); 108 109 /** 110 * Base class for ccs.ActionScaleFrame 111 * @class 112 * @extends ccs.ActionFrame 113 */ 114 ccs.ActionScaleFrame = ccs.ActionFrame.extend(/** @lends ccs.ActionScaleFrame# */{ 115 _scaleX: 1, 116 _scaleY: 1, 117 ctor: function () { 118 ccs.ActionFrame.prototype.ctor.call(this); 119 this._scaleX = 1; 120 this._scaleY = 1; 121 this.frameType = ccs.FRAME_TYPE_SCALE; 122 }, 123 124 /** 125 * Changes the scale action scaleX. 126 * @param {number} scaleX 127 */ 128 setScaleX: function (scaleX) { 129 this._scaleX = scaleX; 130 }, 131 132 /** 133 * Gets the scale action scaleX. 134 * @returns {number} {number} 135 */ 136 getScaleX: function () { 137 return this._scaleX; 138 }, 139 140 /** 141 * Changes the scale action scaleY. 142 * @param {number} scaleY 143 */ 144 setScaleY: function (scaleY) { 145 this._scaleY = scaleY; 146 }, 147 148 /** 149 * Gets the scale action scaleY. 150 * @returns {number} 151 */ 152 getScaleY: function () { 153 return this._scaleY; 154 }, 155 156 /** 157 * Gets the action of ActionFrame. 158 * @param duration 159 * @returns {cc.ScaleTo} 160 */ 161 getAction: function (duration) { 162 return cc.ScaleTo.create(duration, this._scaleX, this._scaleY); 163 } 164 }); 165 166 /** 167 * Base class for ccs.ActionRotationFrame 168 * @class 169 * @extends ccs.ActionFrame 170 */ 171 ccs.ActionRotationFrame = ccs.ActionFrame.extend(/** @lends ccs.ActionRotationFrame# */{ 172 _rotation: 0, 173 ctor: function () { 174 ccs.ActionFrame.prototype.ctor.call(this); 175 this._rotation = 0; 176 this.frameType = ccs.FRAME_TYPE_ROTATE; 177 }, 178 179 /** 180 * Changes rotate action rotation. 181 * @param {number} rotation 182 */ 183 setRotation: function (rotation) { 184 this._rotation = rotation; 185 }, 186 187 /** 188 * Gets the rotate action rotation. 189 * @returns {number} 190 */ 191 getRotation: function () { 192 return this._rotation; 193 }, 194 195 /** 196 * Gets the CCAction of ActionFrame. 197 * @param {number} duration 198 * @returns {cc.RotateTo} 199 */ 200 getAction: function (duration) { 201 return cc.RotateTo.create(duration, this._rotation); 202 } 203 }); 204 205 /** 206 * Base class for ccs.ActionFadeFrame 207 * @class 208 * @extends ccs.ActionFrame 209 */ 210 ccs.ActionFadeFrame = ccs.ActionFrame.extend(/** @lends ccs.ActionFadeFrame# */{ 211 _opacity: 255, 212 ctor: function () { 213 ccs.ActionFrame.prototype.ctor.call(this); 214 this._opacity = 255; 215 this.frameType = ccs.FRAME_TYPE_FADE; 216 }, 217 218 /** 219 * Changes the fade action opacity. 220 * @param {number} opacity 221 */ 222 setOpacity: function (opacity) { 223 this._opacity = opacity; 224 }, 225 226 /** 227 * Gets the fade action opacity. 228 * @returns {number} 229 */ 230 getOpacity: function () { 231 return this._opacity; 232 }, 233 234 /** 235 * Gets the CCAction of ActionFrame. 236 * @param duration 237 * @returns {cc.FadeTo} 238 */ 239 getAction: function (duration) { 240 return cc.FadeTo.create(duration, this._opacity); 241 } 242 }); 243 244 /** 245 * Base class for ccs.ActionTintFrame 246 * @class 247 * @extends ccs.ActionFrame 248 */ 249 ccs.ActionTintFrame = ccs.ActionFrame.extend(/** @lends ccs.ActionTintFrame# */{ 250 _color: null, 251 ctor: function () { 252 ccs.ActionFrame.prototype.ctor.call(this); 253 this._color = cc.color(255, 255, 255, 255); 254 this.frameType = ccs.FRAME_TYPE_TINT; 255 }, 256 257 /** 258 * Changes the tint action color. 259 * @param {cc.Color} color 260 */ 261 setColor: function (color) { 262 var locColor = this._color; 263 locColor.r = color.r; 264 locColor.g = color.g; 265 locColor.b = color.b; 266 }, 267 268 /** 269 * Gets the tint action color. 270 * @returns {cc.Color} 271 */ 272 getColor: function () { 273 var locColor = this._color; 274 return cc.color(locColor.r, locColor.g, locColor.b, locColor.a); 275 }, 276 277 /** 278 * Gets the action of ActionFrame. 279 * @param duration 280 * @returns {cc.TintTo} 281 */ 282 getAction: function (duration) { 283 return cc.TintTo.create(duration, this._color.r, this._color.g, this._color.b); 284 } 285 });