diff --git a/extensions/cocostudio/armature/CCArmature.js b/extensions/cocostudio/armature/CCArmature.js index 540bed7164..b7cc12c406 100644 --- a/extensions/cocostudio/armature/CCArmature.js +++ b/extensions/cocostudio/armature/CCArmature.js @@ -24,7 +24,7 @@ ****************************************************************************/ /** - * Base class for ccs.Armature objects. + * The main class of Armature, it plays armature animation, manages and updates bones' state. * @class * @extends ccs.Node * @@ -70,7 +70,6 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ this._offsetPoint = cc.p(0, 0); this._armatureTransformDirty = true; this._realAnchorPointInPoints = cc.p(0, 0); - name && ccs.Armature.prototype.init.call(this, name, parentBone); }, @@ -277,6 +276,12 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ this.setAnchorPoint(locOffsetPoint.x / rect.width, locOffsetPoint.y / rect.height); }, + /** + * Sets armature's anchor point, because it need to consider offset point, so here is the override function. + * @override + * @param {cc.Point|Number} point point or x of point + * @param {Number} [y] y of point + */ setAnchorPoint: function(point, y){ var ax, ay; if(y !== undefined){ @@ -316,6 +321,11 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ this.setNodeDirty(); }, + /** + * Returns the anchor point in points of ccs.Armature. + * @override + * @returns {cc.Point} + */ getAnchorPointInPoints: function(){ return this._realAnchorPointInPoints; }, @@ -344,6 +354,11 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ return this._armatureTransformDirty; }, + /** + * The update callback of ccs.Armature, it updates animation's state and updates bone's state. + * @override + * @param {Number} dt + */ update: function (dt) { this.animation.update(dt); var locTopBoneList = this._topBoneList; @@ -352,6 +367,11 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ this._armatureTransformDirty = false; }, + /** + * Draws armature's display render node. + * @override + * @param {CanvasRenderingContext2D | WebGLRenderingContext} ctx The render context + */ draw: function(ctx){ if (this._parentBone == null && this._batchNode == null) { // CC_NODE_DRAW_SETUP(); @@ -408,11 +428,19 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ } }, + /** + * The callback when ccs.Armature enter stage. + * @override + */ onEnter: function () { cc.Node.prototype.onEnter.call(this); this.scheduleUpdate(); }, + /** + * The callback when ccs.Armature exit stage. + * @override + */ onExit: function () { cc.Node.prototype.onExit.call(this); this.unscheduleUpdate(); @@ -531,7 +559,7 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ }, /** - * return parent bone + * Return parent bone of ccs.Armature. * @returns {ccs.Bone} */ getParentBone: function () { @@ -559,6 +587,7 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ } }, + setBody: function (body) { if (this._body == body) return; @@ -591,7 +620,7 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ }, /** - * conforms to cc.TextureProtocol protocol + * Sets the blendFunc to ccs.Armature * @param {cc.BlendFunc} blendFunc */ setBlendFunc: function (blendFunc) { @@ -599,7 +628,7 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ }, /** - * blendFunc getter + * Returns the blendFunc of ccs.Armature * @returns {cc.BlendFunc} */ getBlendFunc: function () { @@ -617,7 +646,7 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ }, /** - * Gets the armatureData of this Armature + * Returns the armatureData of ccs.Armature * @return {ccs.ArmatureData} */ getArmatureData: function () { diff --git a/extensions/cocostudio/armature/CCBone.js b/extensions/cocostudio/armature/CCBone.js index 62e22f604a..8a4d1d78a5 100644 --- a/extensions/cocostudio/armature/CCBone.js +++ b/extensions/cocostudio/armature/CCBone.js @@ -24,7 +24,7 @@ ****************************************************************************/ /** - * Base class for ccs.Bone objects. + * The Bone of Armature, it has bone data, display manager and transform data for armature. * @class * @extends ccs.Node * @@ -53,12 +53,16 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ _parentBone: null, _boneTransformDirty: false, _worldTransform: null, - _blendFunc: 0, + _blendFunc: null, blendDirty: false, _worldInfo: null, _armatureParentBone: null, _dataVersion: 0, _className: "Bone", + + /** + * Construction of ccs.Bone. + */ ctor: function () { cc.Node.prototype.ctor.call(this); this._tweenData = null; @@ -81,15 +85,14 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * Initializes a CCBone with the specified name - * @param {String} name + * Initializes a ccs.Bone with the specified name + * @param {String} name bone name * @return {Boolean} */ init: function (name) { // cc.Node.prototype.init.call(this); - if (name) { + if (name) this._name = name; - } this._tweenData = new ccs.FrameData(); this._tween = new ccs.Tween(); @@ -105,7 +108,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * set the boneData + * Sets the boneData to ccs.Bone. * @param {ccs.BoneData} boneData */ setBoneData: function (boneData) { @@ -120,7 +123,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * boneData getter + * Returns boneData of ccs.Bone. * @return {ccs.BoneData} */ getBoneData: function () { @@ -128,7 +131,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * set the armature + * Sets the armature reference to ccs.Bone. * @param {ccs.Armature} armature */ setArmature: function (armature) { @@ -137,13 +140,12 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ this._tween.setAnimation(this._armature.getAnimation()); this._dataVersion = this._armature.getArmatureData().dataVersion; this._armatureParentBone = this._armature.getParentBone(); - } else { + } else this._armatureParentBone = null; - } }, /** - * armature getter + * Returns the armature reference of ccs.Bone. * @return {ccs.Armature} */ getArmature: function () { @@ -151,7 +153,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * update worldTransform + * Updates worldTransform by tween data and updates display state * @param {Number} delta */ update: function (delta) { @@ -179,10 +181,10 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ locWorldInfo.skewY = locTweenData.skewY + this._skewY - this._rotationY; if(this._parentBone) - this.applyParentTransform(this._parentBone); + this._applyParentTransform(this._parentBone); else { if (this._armatureParentBone) - this.applyParentTransform(this._armatureParentBone); + this._applyParentTransform(this._armatureParentBone); } ccs.TransformHelp.nodeToMatrix(locWorldInfo, this._worldTransform); @@ -198,7 +200,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ this._boneTransformDirty = false; }, - applyParentTransform: function (parent) { + _applyParentTransform: function (parent) { var locWorldInfo = this._worldInfo; var locParentWorldTransform = parent._worldTransform; var locParentWorldInfo = parent._worldInfo; @@ -213,18 +215,29 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * BlendFunc setter - * @param {cc.BlendFunc} blendFunc + * Sets BlendFunc to ccs.Bone. + * @param {cc.BlendFunc|Number} blendFunc blendFunc or src of blendFunc + * @param {Number} [dst] dst of blendFunc */ - setBlendFunc: function (blendFunc) { - if (this._blendFunc.src != blendFunc.src || this._blendFunc.dst != blendFunc.dst) { - this._blendFunc = blendFunc; + setBlendFunc: function (blendFunc, dst) { + var locBlendFunc = this._blendFunc, srcValue, dstValue; + if(dst === undefined){ + srcValue = blendFunc.src; + dstValue = blendFunc.dst; + } else { + srcValue = blendFunc; + dstValue = dst; + } + if (locBlendFunc.src != srcValue || locBlendFunc.dst != dstValue) { + locBlendFunc.src = srcValue; + locBlendFunc.dst = dstValue; this.blendDirty = true; } }, /** - * update display color + * Updates display color + * @override * @param {cc.Color} color */ updateDisplayedColor: function (color) { @@ -234,7 +247,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * update display opacity + * Updates display opacity * @param {Number} opacity */ updateDisplayedOpacity: function (opacity) { @@ -244,7 +257,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * update display color + * Updates display color */ updateColor: function () { var display = this._displayManager.getDisplayRenderNode(); @@ -259,7 +272,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * update display zOrder + * Updates display zOrder */ updateZOrder: function () { if (this._armature.getArmatureData().dataVersion >= ccs.CONST_VERSION_COMBINED) { @@ -271,7 +284,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * Add a child to this bone, and it will let this child call setParent(ccs.Bone) function to set self to it's parent + * Adds a child to this bone, and it will let this child call setParent(ccs.Bone) function to set self to it's parent * @param {ccs.Bone} child */ addChildBone: function (child) { @@ -306,31 +319,34 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * Remove itself from its parent CCBone. + * Removes itself from its parent ccs.Bone. * @param {Boolean} recursion */ removeFromParent: function (recursion) { - if (this._parentBone) { + if (this._parentBone) this._parentBone.removeChildBone(this, recursion); - } }, /** - * Set parent bone. + * Sets parent bone to ccs.Bone. * If _parent is NUll, then also remove this bone from armature. - * It will not set the CCArmature, if you want to add the bone to a CCArmature, you should use ccs.Armature.addBone(bone, parentName). + * It will not set the ccs.Armature, if you want to add the bone to a ccs.Armature, you should use ccs.Armature.addBone(bone, parentName). * @param {ccs.Bone} parent the parent bone. */ setParentBone: function (parent) { this._parentBone = parent; }, + /** + * Returns the parent bone of ccs.Bone. + * @returns {ccs.Bone} + */ getParentBone: function(){ return this._parentBone; }, /** - * child armature setter + * Sets ccs.Bone's child armature * @param {ccs.Armature} armature */ setChildArmature: function (armature) { @@ -342,7 +358,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * child armature getter + * Returns ccs.Bone's child armature. * @return {ccs.Armature} */ getChildArmature: function () { @@ -350,7 +366,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * tween getter + * Return the tween of ccs.Bone * @return {ccs.Tween} */ getTween: function () { @@ -358,7 +374,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * zOrder setter + * Sets the local zOrder to ccs.Bone. * @param {Number} zOrder */ setLocalZOrder: function (zOrder) { @@ -366,16 +382,25 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ cc.Node.prototype.setLocalZOrder.call(this, zOrder); }, + /** + * Return the worldTransform of ccs.Bone. + * @returns {cc.AffineTransform} + */ getNodeToArmatureTransform: function(){ return this._worldTransform; }, + /** + * Returns the world transform of ccs.Bone. + * @override + * @returns {cc.AffineTransform} + */ getNodeToWorldTransform: function(){ return cc.affineTransformConcat(this._worldTransform, this._armature.getNodeToWorldTransform()); }, /** - * get render node + * Returns the display render node. * @returns {cc.Node} */ getDisplayRenderNode: function () { @@ -383,7 +408,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * get render node type + * Returns the type of display render node * @returns {Number} */ getDisplayRenderNodeType: function () { @@ -405,15 +430,16 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * remove display - * @param {Number} index + * Removes display by index. + * @param {Number} index display renderer's index */ removeDisplay: function (index) { this._displayManager.removeDisplay(index); }, /** - * change display by index + * Changes display by index + * @deprecated since v3.0, please use changeDisplayWithIndex instead. * @param {Number} index * @param {Boolean} force */ @@ -422,12 +448,19 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ this.changeDisplayWithIndex(index, force); }, + /** + * Changes display by name + * @deprecated since v3.0, please use changeDisplayWithName instead. + * @param {String} name + * @param {Boolean} force + */ changeDisplayByName: function(name, force){ + cc.log("changeDisplayByName is deprecated. Use changeDisplayWithName instead."); this.changeDisplayWithName(name, force); }, /** - * change display with index + * Changes display with index * @param {Number} index * @param {Boolean} force */ @@ -436,7 +469,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * change display with name + * Changes display with name * @param {String} name * @param {Boolean} force */ @@ -444,6 +477,10 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ this._displayManager.changeDisplayWithName(name, force); }, + /** + * Returns the collide detector of ccs.Bone. + * @returns {*} + */ getColliderDetector: function(){ var decoDisplay = this._displayManager.getCurrentDecorativeDisplay(); if (decoDisplay){ @@ -455,22 +492,21 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * collider filter setter - * @param {cc.ColliderFilter} filter + * Sets collider filter to ccs.Bone. + * @param {ccs.ColliderFilter} filter */ setColliderFilter: function (filter) { var displayList = this._displayManager.getDecorativeDisplayList(); for (var i = 0; i < displayList.length; i++) { var locDecoDisplay = displayList[i]; var locDetector = locDecoDisplay.getColliderDetector(); - if (locDetector) { + if (locDetector) locDetector.setColliderFilter(filter); - } } }, /** - * collider filter getter + * Returns collider filter of ccs.Bone. * @returns {cc.ColliderFilter} */ getColliderFilter: function () { @@ -484,7 +520,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * transform dirty setter + * Sets ccs.Bone's transform dirty flag. * @param {Boolean} dirty */ setTransformDirty: function (dirty) { @@ -492,7 +528,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * transform dirty getter + * Returns ccs.Bone's transform dirty flag whether is dirty. * @return {Boolean} */ isTransformDirty: function () { @@ -508,7 +544,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * When CCArmature play a animation, if there is not a CCMovementBoneData of this bone in this CCMovementData, this bone will hide. + * When CCArmature play a animation, if there is not a CCMovementBoneData of this bone in this CCMovementData, this bone will hide.
* Set IgnoreMovementBoneData to true, then this bone will also show. * @param {Boolean} bool */ @@ -516,51 +552,67 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ this._ignoreMovementBoneData = bool; }, + /** + * Returns whether is ignore movement bone data. + * @returns {Boolean} + */ isIgnoreMovementBoneData: function(){ return this._ignoreMovementBoneData; }, /** - * blendType getter + * Returns the blendFunc of ccs.Bone. * @return {cc.BlendFunc} */ getBlendFunc: function () { return this._blendFunc; }, + /** + * Sets blend dirty flag + * @param {Boolean} dirty + */ setBlendDirty: function (dirty) { this._blendDirty = dirty; }, + /** + * Returns the blend dirty flag whether is dirty. + * @returns {Boolean|*|ccs.Bone._blendDirty} + */ isBlendDirty: function () { return this._blendDirty; }, /** - * tweenData getter + * Returns the tweenData of ccs.Bone. * @return {ccs.FrameData} */ getTweenData: function () { return this._tweenData; }, + /** + * Returns the world information of ccs.Bone. + * @returns {ccs.BaseData} + */ getWorldInfo: function(){ return this._worldInfo; }, /** - * child bone getter + * Returns the children of ccs.Bone * @return {Array} - * @deprecated + * @deprecated since v3.0, please use getChildren instead. */ getChildrenBone: function () { return this._children; }, /** - * @deprecated - * return world transform - * @return {{a:0.b:0,c:0,d:0,tx:0,ty:0}} + * Returns the worldTransform of ccs.Bone. + * @return {cc.AffineTransform} + * @deprecated since v3.0, please use getNodeToArmatureTransform instead. */ nodeToArmatureTransform: function () { return this.getNodeToArmatureTransform(); @@ -576,9 +628,9 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * @deprecated - * get the collider body list in this bone. - * @returns {*} + * Returns the collider body list in this bone. + * @returns {Array|null} + * @deprecated since v3.0, please use getColliderDetector to get a delector, and calls its getColliderBodyList instead. */ getColliderBodyList: function () { var detector = this.getColliderDetector(); @@ -588,8 +640,9 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ }, /** - * ignoreMovementBoneData getter + * Returns whether is ignore movement bone data. * @return {Boolean} + * @deprecated since v3.0, please isIgnoreMovementBoneData instead. */ getIgnoreMovementBoneData: function () { return this.isIgnoreMovementBoneData(); @@ -624,8 +677,7 @@ cc.defineGetterSetter(_p, "colliderFilter", _p.getColliderFilter, _p.setCollider _p = null; /** - * allocates and initializes a bone. - * @constructs + * Allocates and initializes a bone. * @return {ccs.Bone} * @example * // example diff --git a/extensions/cocostudio/armature/animation/CCArmatureAnimation.js b/extensions/cocostudio/armature/animation/CCArmatureAnimation.js index 272d74c3c1..566e24b24b 100644 --- a/extensions/cocostudio/armature/animation/CCArmatureAnimation.js +++ b/extensions/cocostudio/armature/animation/CCArmatureAnimation.js @@ -24,7 +24,8 @@ ****************************************************************************/ /** - * movement event type + * movement event type enum + * @constant * @type {Object} */ ccs.MovementEventType = { @@ -32,8 +33,10 @@ ccs.MovementEventType = { complete: 1, loopComplete: 2 }; + /** - * Base class for cc.MovementEvent objects. + * The animation event class, it has the callback, target and arguments. + * @deprecated since v3.0. * @class * @extends ccs.Class */ @@ -43,7 +46,7 @@ ccs.AnimationEvent = ccs.Class.extend(/** @lends ccs.AnimationEvent# */{ _selectorTarget: null, /** - * + * Constructor of ccs.AnimationEvent * @param {function} callFunc * @param {object} target * @param {object} [data] @@ -54,26 +57,36 @@ ccs.AnimationEvent = ccs.Class.extend(/** @lends ccs.AnimationEvent# */{ this._selectorTarget = target; }, call: function () { - if (this._callFunc) { + if (this._callFunc) this._callFunc.apply(this._selectorTarget, this._arguments); - } }, setArguments: function (args) { this._arguments = args; } }); + /** - * movement event + * The movement event class for Armature. * @constructor + * + * @property {ccs.Armature} armature - The armature reference of movement event. + * @property {Number} movementType - The type of movement. + * @property {String} movementID - The ID of movement. */ ccs.MovementEvent = function () { this.armature = null; - this.movementType = ""; + this.movementType = ccs.MovementEventType.start; this.movementID = ""; }; + /** - * frame event + * The frame event class for Armature. * @constructor + * + * @property {ccs.Bone} bone - The bone reference of frame event. + * @property {String} frameEventName - The name of frame event. + * @property {Number} originFrameIndex - The index of origin frame. + * @property {Number} currentFrameIndex - The index of current frame. */ ccs.FrameEvent = function () { this.bone = null; @@ -81,8 +94,9 @@ ccs.FrameEvent = function () { this.originFrameIndex = 0; this.currentFrameIndex = 0; }; + /** - * Base class for ccs.ArmatureAnimation objects. + * The Animation class for Armature, it plays armature animation, and controls speed scale and manages animation frame. * @class * @extends ccs.ProcessBase * @@ -91,7 +105,6 @@ ccs.FrameEvent = function () { * @property {Boolean} ignoreFrameEvent - Indicate whether the frame event is ignored * @property {Number} speedScale - Animation play speed scale * @property {Number} animationScale - Animation play speed scale - * */ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# */{ _animationData: null, @@ -117,6 +130,9 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# _movementEventListener: null, _frameEventListener: null, + /** + * The Construction of ccs.ArmatureAnimation + */ ctor: function () { ccs.ProcessBase.prototype.ctor.call(this); @@ -127,7 +143,7 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# }, /** - * init with a CCArmature + * Initializes with an armature object * @param {ccs.Armature} armature * @return {Boolean} */ @@ -137,6 +153,9 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# return true; }, + /** + * Pauses armature animation. + */ pause: function () { var locTweenList = this._tweenList; for (var i = 0; i < locTweenList.length; i++) @@ -144,6 +163,9 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# ccs.ProcessBase.prototype.pause.call(this); }, + /** + * Resumes armature animation. + */ resume: function () { var locTweenList = this._tweenList; for (var i = 0; i < locTweenList.length; i++) @@ -151,6 +173,9 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# ccs.ProcessBase.prototype.resume.call(this); }, + /** + * Stops armature animation. + */ stop: function () { var locTweenList = this._tweenList; for (var i = 0; i < locTweenList.length; i++) @@ -159,16 +184,26 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# ccs.ProcessBase.prototype.stop.call(this); }, + /** + * Sets animation play speed scale. + * @deprecated since v3.0, please use setSpeedScale instead. + * @param {Number} animationScale + */ setAnimationScale: function (animationScale) { - return this.setSpeedScale(animationScale); + this.setSpeedScale(animationScale); }, + /** + * Returns animation play speed scale. + * @deprecated since v3.0, please use getSpeedScale instead. + * @returns {Number} + */ getAnimationScale: function () { return this.getSpeedScale(); }, /** - * scale animation play speed + * Sets animation play speed scale. * @param {Number} speedScale */ setSpeedScale: function (speedScale) { @@ -185,6 +220,10 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# } }, + /** + * Returns animation play speed scale. + * @returns {Number} + */ getSpeedScale: function () { return this._speedScale; }, @@ -266,12 +305,13 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# }, /** - * Play animation with index, the o ther param is the same to play. + * Plays animation with index, the other param is the same to play. * @param {Number} animationIndex * @param {Number} durationTo * @param {Number} durationTween * @param {Number} loop - * @param {Number} tweenEasing + * @param {Number} [tweenEasing] + * @deprecated since v3.0, please use playWithIndex instead. */ playByIndex: function (animationIndex, durationTo, durationTween, loop, tweenEasing) { cc.log("playByIndex is deprecated. Use playWithIndex instead."); @@ -279,8 +319,8 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# }, /** - * Play animation with index, the other param is the same to play. - * @param {Number||Array} animationIndex + * Plays animation with index, the other param is the same to play. + * @param {Number|Array} animationIndex * @param {Number} durationTo * @param {Number} loop */ @@ -293,7 +333,7 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# }, /** - * play with names + * Plays animation with names * @param {Array} movementNames * @param {Number} durationTo * @param {Boolean} loop @@ -310,13 +350,12 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# this._movementList = movementNames; else this._movementList.length = 0; - this.updateMovementList(); }, /** - * play by indexes - * @param movementIndexes + * Plays animation by indexes + * @param {Array} movementIndexes * @param {Number} durationTo * @param {Boolean} loop */ @@ -341,14 +380,16 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# }, /** - * Go to specified frame and play current movement. - * You need first switch to the movement you want to play, then call this function. - * - * example : playByIndex(0); - * gotoAndPlay(0); - * playByIndex(1); - * gotoAndPlay(0); - * gotoAndPlay(15); + *

+ * Goes to specified frame and plays current movement.
+ * You need first switch to the movement you want to play, then call this function.
+ *
+ * example : playByIndex(0);
+ * gotoAndPlay(0);
+ * playByIndex(1);
+ * gotoAndPlay(0);
+ * gotoAndPlay(15);
+ *

* @param {Number} frameIndex */ gotoAndPlay: function (frameIndex) { @@ -367,15 +408,14 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# this._currentFrame = this._nextFrameIndex * this._currentPercent; var locTweenList = this._tweenList; - for (var i = 0; i < locTweenList.length; i++) { + for (var i = 0; i < locTweenList.length; i++) locTweenList[i].gotoAndPlay(frameIndex); - } this._armature.update(0); this._ignoreFrameEvent = ignoreFrameEvent; }, /** - * Go to specified frame and pause current movement. + * Goes to specified frame and pauses current movement. * @param {Number} frameIndex */ gotoAndPause: function (frameIndex) { @@ -384,13 +424,17 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# }, /** - * get movement count + * Returns the length of armature's movements * @return {Number} */ getMovementCount: function () { return this._animationData.getMovementCount(); }, + /** + * Updates the state of ccs.Tween list, calls frame event's callback and calls movement event's callback. + * @param {Number} dt + */ update: function (dt) { ccs.ProcessBase.prototype.update.call(this, dt); @@ -420,9 +464,9 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# }, /** - * update will call this handler, you can handle your logic here + * Updates will call this handler, you can handle your logic here */ - updateHandler: function () { + updateHandler: function () { //TODO set it to protected in v3.1 var locCurrentPercent = this._currentPercent; if (locCurrentPercent >= 1) { switch (this._loopType) { @@ -465,7 +509,7 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# }, /** - * Get current movementID + * Returns the Id of current movement * @returns {String} */ getCurrentMovementID: function () { @@ -475,7 +519,7 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# }, /** - * connect a event + * Sets movement event callback to animation. * @param {function} callFunc * @param {Object} target */ @@ -489,7 +533,7 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# }, /** - * connect a event + * Sets frame event callback to animation. * @param {function} callFunc * @param {Object} target */ @@ -503,7 +547,7 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# }, /** - * userObject setter + * Sets user object to animation. * @param {Object} userObject */ setUserObject: function (userObject) { @@ -511,6 +555,7 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# }, /** + * Emits a frame event * @param {ccs.Bone} bone * @param {String} frameEventName * @param {Number} originFrameIndex @@ -523,11 +568,16 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# frameEvent.frameEventName = frameEventName; frameEvent.originFrameIndex = originFrameIndex; frameEvent.currentFrameIndex = currentFrameIndex; - this._frameEventQueue.push(frameEvent); } }, + /** + * Emits a movement event + * @param {ccs.Armature} armature + * @param {Number} movementType + * @param {String} movementID + */ movementEvent: function (armature, movementType, movementID) { if ((this._movementEventTarget && this._movementEventCallFunc) || this._movementEventListener) { var event = new ccs.MovementEvent(); @@ -538,6 +588,9 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# } }, + /** + * Updates movement list. + */ updateMovementList: function () { if (this._onMovementList) { var movementObj, locMovementList = this._movementList; @@ -560,7 +613,7 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# }, /** - * animationData setter + * Sets animation data to animation. * @param {ccs.AnimationData} data */ setAnimationData: function (data) { @@ -569,7 +622,7 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# }, /** - * animationData getter + * Returns animation data of animation. * @return {ccs.AnimationData} */ getAnimationData: function () { @@ -577,7 +630,7 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# }, /** - * userObject getter + * Returns the user object of animation. * @return {Object} */ getUserObject: function () { @@ -606,17 +659,15 @@ cc.defineGetterSetter(_p, "animationScale", _p.getAnimationScale, _p.setAnimatio _p = null; /** - * allocates and initializes a ArmatureAnimation. - * @constructs + * Allocates and initializes a ArmatureAnimation. * @return {ccs.ArmatureAnimation} * @example * // example * var animation = ccs.ArmatureAnimation.create(); */ -ccs.ArmatureAnimation.create = function (armature) { +ccs.ArmatureAnimation.create = function (armature) { //TODO it will be deprecated in v3.1 var animation = new ccs.ArmatureAnimation(); - if (animation && animation.init(armature)) { + if (animation && animation.init(armature)) return animation; - } return null; }; \ No newline at end of file diff --git a/extensions/cocostudio/armature/animation/CCProcessBase.js b/extensions/cocostudio/armature/animation/CCProcessBase.js index 9af6f06399..9f2ec90f78 100644 --- a/extensions/cocostudio/armature/animation/CCProcessBase.js +++ b/extensions/cocostudio/armature/animation/CCProcessBase.js @@ -23,53 +23,52 @@ THE SOFTWARE. ****************************************************************************/ - //animation type /** - * the animation just have one frame + * The animation just have one frame * @constant * @type {number} */ ccs.ANIMATION_TYPE_SINGLE_FRAME = -4; /** - * the animation isn't loop + * The animation isn't loop * @constant * @type {number} */ ccs.ANIMATION_TYPE_NO_LOOP = -3; /** - * the animation to loop from front + * The animation to loop from front * @constant * @type {number} */ ccs.ANIMATION_TYPE_TO_LOOP_FRONT = -2; /** - * the animation to loop from back + * The animation to loop from back * @constant * @type {number} */ ccs.ANIMATION_TYPE_TO_LOOP_BACK = -1; /** - * the animation loop from front + * The animation loop from front * @constant * @type {number} */ ccs.ANIMATION_TYPE_LOOP_FRONT = 0; /** - * the animation loop from back + * The animation loop from back * @constant * @type {number} */ ccs.ANIMATION_TYPE_LOOP_BACK = 1; /** - * the animation max + * The animation max * @constant * @type {number} */ ccs.ANIMATION_TYPE_MAX = 2; /** - * Base class for ccs.ProcessBase objects. + * The Base Process class for Cocostudio. * @class * @extends ccs.Class * @@ -100,6 +99,9 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ _curFrameIndex: null, _isLoopBack: false, + /** + * Constructor of ccs.ProcessBase + */ ctor: function () { this._processScale = 1; this._isComplete = true; @@ -118,7 +120,7 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ }, /** - * Pause the Process + * Pauses the Process */ pause: function () { this._isPause = true; @@ -126,7 +128,7 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ }, /** - * Resume the Process + * Resumes the Process */ resume: function () { this._isPause = false; @@ -134,7 +136,7 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ }, /** - * Stop the Process + * Stops the Process */ stop: function () { this._isComplete = true; @@ -142,7 +144,7 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ }, /** - * Play animation by animation name. + * Plays animation by animation name. * @param {Number} durationTo The frames between two animation changing-over. * It's meaning is changing to this animation need how many frames * -1 : use the value from MovementData get from flash design panel @@ -173,6 +175,10 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ this._tweenEasing = tweenEasing; }, + /** + * Update process' state. + * @param {Number} dt + */ update: function (dt) { if (this._isComplete || this._isPause) return; @@ -209,7 +215,7 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ }, /** - * goto frame + * Goes to specified frame by frameIndex. * @param {Number} frameIndex */ gotoFrame: function (frameIndex) { @@ -224,7 +230,7 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ }, /** - * get currentFrameIndex + * Returns the index of current frame. * @return {Number} */ getCurrentFrameIndex: function () { @@ -233,14 +239,14 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ }, /** - * update will call this handler, you can handle your logic here + * Updates will call this handler, you can handle your logic here */ updateHandler: function () { //override }, /** - * whether the animation is pause + * Returns whether the animation is pause * @returns {boolean} */ isPause: function () { @@ -248,7 +254,7 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ }, /** - * whether the animation is complete + * Returns whether the animation is complete * @returns {boolean} */ isComplete: function () { @@ -256,7 +262,7 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ }, /** - * current percent getter + * Returns current percent of ccs.ProcessBase * @returns {number} */ getCurrentPercent: function () { @@ -264,7 +270,7 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ }, /** - * rawDuration getter + * Returns the raw duration of ccs.ProcessBase * @returns {number} */ getRawDuration: function () { @@ -272,7 +278,7 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ }, /** - * loop type getter + * Returns loop type of ccs.ProcessBase * @returns {number} */ getLoop: function () { @@ -280,7 +286,7 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ }, /** - * tween easing getter + * Returns tween easing of ccs.ProcessBase * @returns {number} */ getTweenEasing: function () { @@ -288,15 +294,15 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ }, /** - * animationInternal getter + * Returns animation interval of ccs.ProcessBase * @returns {number} */ - getAnimationInternal: function () { + getAnimationInternal: function () { //TODO rename getAnimationInternal to getAnimationInterval in v3.1 return this.animationInternal; }, /** - * animationInternal setter + * Sets animation interval to ccs.ProcessBase. * @param animationInternal */ setAnimationInternal: function (animationInternal) { @@ -304,7 +310,7 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ }, /** - * process scale getter + * Returns process scale * @returns {number} */ getProcessScale: function () { @@ -312,7 +318,7 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ }, /** - * process scale setter + * Sets process scale * @param processScale */ setProcessScale: function (processScale) { @@ -320,7 +326,7 @@ ccs.ProcessBase = ccs.Class.extend(/** @lends ccs.ProcessBase# */{ }, /** - * whether the animation is playing + * Returns whether the animation is playing * @returns {boolean} */ isPlaying: function () { diff --git a/extensions/cocostudio/armature/animation/CCTween.js b/extensions/cocostudio/armature/animation/CCTween.js index 5dfa330286..fb86b5ffd2 100644 --- a/extensions/cocostudio/armature/animation/CCTween.js +++ b/extensions/cocostudio/armature/animation/CCTween.js @@ -24,7 +24,7 @@ ****************************************************************************/ /** - * Base class for ccs.Tween objects. + * The tween class for Armature. * @class * @extends ccs.ProcessBase * @@ -45,13 +45,16 @@ ccs.Tween = ccs.ProcessBase.extend(/** @lends ccs.Tween# */{ _animation:null, _passLastFrame:false, + /** + * Construction of ccs.Tween. + */ ctor:function () { ccs.ProcessBase.prototype.ctor.call(this); this._frameTweenEasing = ccs.TweenType.linear; }, /** - * init with a CCBone + * initializes a ccs.Tween with a CCBone * @param {ccs.Bone} bone * @return {Boolean} */ @@ -70,7 +73,7 @@ ccs.Tween = ccs.ProcessBase.extend(/** @lends ccs.Tween# */{ }, /** - * Start the Process + * Plays the tween. * @param {ccs.MovementBoneData} movementBoneData * @param {Number} durationTo * @param {Number} durationTween @@ -121,6 +124,10 @@ ccs.Tween = ccs.ProcessBase.extend(/** @lends ccs.Tween# */{ this.tweenNodeTo(0); }, + /** + * Goes to specified frame and plays frame. + * @param {Number} frameIndex + */ gotoAndPlay: function (frameIndex) { ccs.ProcessBase.prototype.gotoFrame.call(this, frameIndex); @@ -135,6 +142,10 @@ ccs.Tween = ccs.ProcessBase.extend(/** @lends ccs.Tween# */{ this._currentFrame = this._nextFrameIndex * this._currentPercent; }, + /** + * Goes to specified frame and pauses frame. + * @param {Number} frameIndex + */ gotoAndPause: function (frameIndex) { this.gotoAndPlay(frameIndex); this.pause(); @@ -217,7 +228,7 @@ ccs.Tween = ccs.ProcessBase.extend(/** @lends ccs.Tween# */{ * @param {ccs.FrameData} to * @param {Boolean} [limit=true] */ - setBetween:function (from, to, limit) { + setBetween:function (from, to, limit) { //TODO set tweenColorTo to protected in v3.1 if(limit === undefined) limit = true; do { @@ -245,7 +256,7 @@ ccs.Tween = ccs.ProcessBase.extend(/** @lends ccs.Tween# */{ * Update display index and process the key frame event when arrived a key frame * @param {ccs.FrameData} keyFrameData */ - arriveKeyFrame:function (keyFrameData) { + arriveKeyFrame:function (keyFrameData) { //TODO set tweenColorTo to protected in v3.1 if (keyFrameData) { var locBone = this._bone; var displayManager = locBone.getDisplayManager(); @@ -270,13 +281,14 @@ ccs.Tween = ccs.ProcessBase.extend(/** @lends ccs.Tween# */{ } } }, + /** * According to the percent to calculate current CCFrameData with tween effect * @param {Number} percent * @param {ccs.FrameData} [node] * @return {ccs.FrameData} */ - tweenNodeTo:function (percent, node) { + tweenNodeTo:function (percent, node) { //TODO set tweenColorTo to protected in v3.1 if (!node) node = this._tweenData; @@ -298,7 +310,12 @@ ccs.Tween = ccs.ProcessBase.extend(/** @lends ccs.Tween# */{ return node; }, - tweenColorTo:function(percent,node){ + /** + * According to the percent to calculate current color with tween effect + * @param {Number} percent + * @param {ccs.FrameData} node + */ + tweenColorTo:function(percent,node){ //TODO set tweenColorTo to protected in v3.1 var locFrom = this._from; var locBetween = this._between; node.a = locFrom.a + percent * locBetween.a; @@ -313,7 +330,7 @@ ccs.Tween = ccs.ProcessBase.extend(/** @lends ccs.Tween# */{ * @param {Number} currentPercent * @return {Number} */ - updateFrameData:function (currentPercent) { + updateFrameData:function (currentPercent) { //TODO set tweenColorTo to protected in v3.1 if (currentPercent > 1 && this._movementBoneData.delay != 0) currentPercent = ccs.fmodf(currentPercent,1); @@ -385,9 +402,8 @@ ccs.Tween = ccs.ProcessBase.extend(/** @lends ccs.Tween# */{ return currentPercent; }, - /** - * animation setter + * Sets Armature animation to ccs.Tween. * @param {ccs.ArmatureAnimation} animation */ setAnimation:function (animation) { @@ -395,13 +411,17 @@ ccs.Tween = ccs.ProcessBase.extend(/** @lends ccs.Tween# */{ }, /** - * animation getter + * Returns Armature animation of ccs.Tween. * @return {ccs.ArmatureAnimation} */ getAnimation:function () { return this._animation; }, + /** + * Sets movement bone data to ccs.Tween. + * @param data + */ setMovementBoneData: function(data){ this._movementBoneData = data; } @@ -417,15 +437,14 @@ cc.defineGetterSetter(_p, "animation", _p.getAnimation, _p.setAnimation); _p = null; /** - * allocates and initializes a ArmatureAnimation. - * @constructs + * Allocates and initializes a ArmatureAnimation. * @param {ccs.Bone} bone * @return {ccs.Tween} * @example * // example * var animation = ccs.ArmatureAnimation.create(); */ -ccs.Tween.create = function (bone) { +ccs.Tween.create = function (bone) { //TODO it will be deprecated in v3.1 var tween = new ccs.Tween(); if (tween && tween.init(bone)) return tween;