1 /**************************************************************************** 2 Copyright (c) 2011-2012 cocos2d-x.org 3 Copyright (c) 2013-2014 Chukong Technologies Inc. 4 5 http://www.cocos2d-x.org 6 7 Permission is hereby granted, free of charge, to any person obtaining a copy 8 of this software and associated documentation files (the "Software"), to deal 9 in the Software without restriction, including without limitation the rights 10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 copies of the Software, and to permit persons to whom the Software is 12 furnished to do so, subject to the following conditions: 13 14 The above copyright notice and this permission notice shall be included in 15 all copies or substantial portions of the Software. 16 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 THE SOFTWARE. 24 ****************************************************************************/ 25 26 //Action frame type 27 /** 28 * @ignore 29 */ 30 ccs.FRAME_TYPE_MOVE = 0; 31 ccs.FRAME_TYPE_SCALE = 1; 32 ccs.FRAME_TYPE_ROTATE = 2; 33 ccs.FRAME_TYPE_TINT = 3; 34 ccs.FRAME_TYPE_FADE = 4; 35 ccs.FRAME_TYPE_MAX = 5; 36 37 /** 38 * Base class for ccs.ActionFrame 39 * @class 40 * @extends ccs.Class 41 */ 42 ccs.ActionFrame = ccs.Class.extend(/** @lends ccs.ActionFrame# */{ 43 frameType: 0, 44 easingType: 0, 45 frameIndex: 0, 46 time: 0, 47 ctor: function () { 48 this.frameType = 0; 49 this.easingType = 0; 50 this.frameIndex = 0; 51 this.time = 0; 52 }, 53 54 /** 55 * Gets the action of ActionFrame. 56 * @param {number} duration 57 * @returns {null} 58 */ 59 getAction: function (duration) { 60 return null; 61 } 62 }); 63 64 /** 65 * Base class for ccs.ActionMoveFrame 66 * @class 67 * @extends ccs.ActionFrame 68 */ 69 ccs.ActionMoveFrame = ccs.ActionFrame.extend(/** @lends ccs.ActionMoveFrame# */{ 70 _position: null, 71 ctor: function () { 72 ccs.ActionFrame.prototype.ctor.call(this); 73 this._position = cc.p(0, 0); 74 this.frameType = ccs.FRAME_TYPE_MOVE; 75 }, 76 77 /** 78 * Changes the move action position. 79 * @param {cc.Point|Number} pos 80 * @param {Number} y 81 */ 82 setPosition: function (pos, y) { 83 if (y === undefined) { 84 this._position.x = pos.x; 85 this._position.y = pos.y; 86 } else { 87 this._position.x = pos; 88 this._position.y = y; 89 } 90 }, 91 92 /** 93 * Gets the move action position. 94 * @returns {cc.Point} 95 */ 96 getPosition: function () { 97 return this._position; 98 }, 99 100 /** 101 * Gets the CCAction of ActionFrame. 102 * @param {number} duration 103 * @returns {cc.MoveTo} 104 */ 105 getAction: function (duration) { 106 return cc.MoveTo.create(duration, this._position); 107 } 108 }); 109 110 /** 111 * Base class for ccs.ActionScaleFrame 112 * @class 113 * @extends ccs.ActionFrame 114 */ 115 ccs.ActionScaleFrame = ccs.ActionFrame.extend(/** @lends ccs.ActionScaleFrame# */{ 116 _scaleX: 1, 117 _scaleY: 1, 118 ctor: function () { 119 ccs.ActionFrame.prototype.ctor.call(this); 120 this._scaleX = 1; 121 this._scaleY = 1; 122 this.frameType = ccs.FRAME_TYPE_SCALE; 123 }, 124 125 /** 126 * Changes the scale action scaleX. 127 * @param {number} scaleX 128 */ 129 setScaleX: function (scaleX) { 130 this._scaleX = scaleX; 131 }, 132 133 /** 134 * Gets the scale action scaleX. 135 * @returns {number} {number} 136 */ 137 getScaleX: function () { 138 return this._scaleX; 139 }, 140 141 /** 142 * Changes the scale action scaleY. 143 * @param {number} scaleY 144 */ 145 setScaleY: function (scaleY) { 146 this._scaleY = scaleY; 147 }, 148 149 /** 150 * Gets the scale action scaleY. 151 * @returns {number} 152 */ 153 getScaleY: function () { 154 return this._scaleY; 155 }, 156 157 /** 158 * Gets the action of ActionFrame. 159 * @param duration 160 * @returns {cc.ScaleTo} 161 */ 162 getAction: function (duration) { 163 return cc.ScaleTo.create(duration, this._scaleX, this._scaleY); 164 } 165 }); 166 167 /** 168 * Base class for ccs.ActionRotationFrame 169 * @class 170 * @extends ccs.ActionFrame 171 */ 172 ccs.ActionRotationFrame = ccs.ActionFrame.extend(/** @lends ccs.ActionRotationFrame# */{ 173 _rotation: 0, 174 ctor: function () { 175 ccs.ActionFrame.prototype.ctor.call(this); 176 this._rotation = 0; 177 this.frameType = ccs.FRAME_TYPE_ROTATE; 178 }, 179 180 /** 181 * Changes rotate action rotation. 182 * @param {number} rotation 183 */ 184 setRotation: function (rotation) { 185 this._rotation = rotation; 186 }, 187 188 /** 189 * Gets the rotate action rotation. 190 * @returns {number} 191 */ 192 getRotation: function () { 193 return this._rotation; 194 }, 195 196 /** 197 * Gets the CCAction of ActionFrame. 198 * @param {number} duration 199 * @returns {cc.RotateTo} 200 */ 201 getAction: function (duration) { 202 return cc.RotateTo.create(duration, this._rotation); 203 } 204 }); 205 206 /** 207 * Base class for ccs.ActionFadeFrame 208 * @class 209 * @extends ccs.ActionFrame 210 */ 211 ccs.ActionFadeFrame = ccs.ActionFrame.extend(/** @lends ccs.ActionFadeFrame# */{ 212 _opacity: 255, 213 ctor: function () { 214 ccs.ActionFrame.prototype.ctor.call(this); 215 this._opacity = 255; 216 this.frameType = ccs.FRAME_TYPE_FADE; 217 }, 218 219 /** 220 * Changes the fade action opacity. 221 * @param {number} opacity 222 */ 223 setOpacity: function (opacity) { 224 this._opacity = opacity; 225 }, 226 227 /** 228 * Gets the fade action opacity. 229 * @returns {number} 230 */ 231 getOpacity: function () { 232 return this._opacity; 233 }, 234 235 /** 236 * Gets the CCAction of ActionFrame. 237 * @param duration 238 * @returns {cc.FadeTo} 239 */ 240 getAction: function (duration) { 241 return cc.FadeTo.create(duration, this._opacity); 242 } 243 }); 244 245 /** 246 * Base class for ccs.ActionTintFrame 247 * @class 248 * @extends ccs.ActionFrame 249 */ 250 ccs.ActionTintFrame = ccs.ActionFrame.extend(/** @lends ccs.ActionTintFrame# */{ 251 _color: null, 252 ctor: function () { 253 ccs.ActionFrame.prototype.ctor.call(this); 254 this._color = cc.color(255, 255, 255, 255); 255 this.frameType = ccs.FRAME_TYPE_TINT; 256 }, 257 258 /** 259 * Changes the tint action color. 260 * @param {cc.Color} color 261 */ 262 setColor: function (color) { 263 var locColor = this._color; 264 locColor.r = color.r; 265 locColor.g = color.g; 266 locColor.b = color.b; 267 }, 268 269 /** 270 * Gets the tint action color. 271 * @returns {cc.Color} 272 */ 273 getColor: function () { 274 var locColor = this._color; 275 return cc.color(locColor.r, locColor.g, locColor.b, locColor.a); 276 }, 277 278 /** 279 * Gets the action of ActionFrame. 280 * @param duration 281 * @returns {cc.TintTo} 282 */ 283 getAction: function (duration) { 284 return cc.TintTo.create(duration, this._color.r, this._color.g, this._color.b); 285 } 286 });