Class cc.Animation
- Defined in: CCAnimation.js
- Extends cc.Class
Constructor Attributes | Constructor Name and Description |
---|---|
cc.Animation(frames, delay, loops)
A cc.Animation object is used to perform animations on the cc.Sprite objects. |
Method Summary
Class Detail
A cc.Animation object is used to perform animations on the cc.Sprite objects.
The cc.Animation object contains cc.SpriteFrame objects, and a possible delay between the frames.
You can animate a cc.Animation object by using the cc.Animate action.
// 1. Creates an empty animation var animation1 = new cc.Animation(); // 2. Create an animation with sprite frames, delay and loops. var spriteFrames = []; var frame = cc.spriteFrameCache.getSpriteFrame("grossini_dance_01.png"); spriteFrames.push(frame); var animation1 = new cc.Animation(spriteFrames); var animation2 = new cc.Animation(spriteFrames, 0.2); var animation2 = new cc.Animation(spriteFrames, 0.2, 2); // 3. Create an animation with animation frames, delay and loops. var animationFrames = []; var frame = new cc.AnimationFrame(); animationFrames.push(frame); var animation1 = new cc.Animation(animationFrames); var animation2 = new cc.Animation(animationFrames, 0.2); var animation3 = new cc.Animation(animationFrames, 0.2, 2); //create an animate with this animation var action = cc.animate(animation1); //run animate sprite.runAction(action);
- Parameters:
- {Array} frames
- {Number} delay
- {Number} loops Optional, Default: 1
Field Detail
- Deprecated:
- since v3.0, please use new construction instead
- See:
- cc.Animation
Method Detail
-
addSpriteFrame(frame)Adds a frame to a cc.Animation, the frame will be added with one "delay unit".
- Parameters:
- {cc.SpriteFrame} frame
-
addSpriteFrameWithFile(fileName)Adds a frame with an image filename. Internally it will create a cc.SpriteFrame and it will add it. The frame will be added with one "delay unit".
- Parameters:
- {String} fileName
-
addSpriteFrameWithTexture(texture, rect)Adds a frame with a texture and a rect. Internally it will create a cc.SpriteFrame and it will add it. The frame will be added with one "delay unit".
- Parameters:
- {cc.Texture2D} texture
- {cc.Rect} rect
-
{cc.Animation} clone()Clone the current animation
- Returns:
- {cc.Animation}
-
{cc.Animation} copy(pZone)Clone the current animation
- Parameters:
- pZone
- Returns:
- {cc.Animation}
-
{cc.Animation} copyWithZone(pZone)Clone the current animation
- Parameters:
- pZone
- Returns:
- {cc.Animation}
-
Creates an animation.
- Parameters:
- {Array} frames
- {Number} delay
- {Number} loops Optional, Default: 1
- Deprecated:
- since v3.0, please use new construction instead
- Returns:
- {cc.Animation}
- See:
- cc.Animation
-
{Number} getDelayPerUnit()Returns delay in seconds of the "delay unit"
- Returns:
- {Number}
-
{Number} getDuration()Returns duration in seconds of the whole animation. It is the result of totalDelayUnits * delayPerUnit
- Returns:
- {Number}
-
{Array} getFrames()Returns the array of animation frames
- Returns:
- {Array}
-
{Number} getLoops()Returns how many times the animation is going to loop. 0 means animation is not animated. 1, animation is executed one time, ...
- Returns:
- {Number}
-
{Boolean} getRestoreOriginalFrame()Returns whether or not it shall restore the original frame when the animation finishes
- Returns:
- {Boolean}
-
{Number} getTotalDelayUnits()Returns total delay units of the cc.Animation.
- Returns:
- {Number}
-
initWithAnimationFrames(arrayOfAnimationFrames, delayPerUnit, loops)Initializes a cc.Animation with cc.AnimationFrame, do not call this method yourself, please pass parameters to constructor to initialize.
- Parameters:
- {Array} arrayOfAnimationFrames
- {Number} delayPerUnit
- {Number} loops Optional, Default: 1
-
initWithSpriteFrames(frames, delay, loops)Initializes a cc.Animation with frames and a delay between frames, do not call this method yourself, please pass parameters to constructor to initialize.
- Parameters:
- {Array} frames
- {Number} delay
- {Number} loops Optional, Default: 1
-
release()
Currently JavaScript Bindings (JSB), in some cases, needs to use retain and release. This is a bug in JSB, and the ugly workaround is to use retain/release. So, these 2 methods were added to be compatible with JSB. This is a hack, and should be removed once JSB fixes the retain/release bug
You will need to retain an object if you created an engine object and haven't added it into the scene graph during the same frame.
Otherwise, JSB's native autorelease pool will consider this object a useless one and release it directly,
when you want to use it later, a "Invalid Native Object" error will be raised.
The retain function can increase a reference count for the native object to avoid it being released,
you need to manually invoke release function when you think this object is no longer needed, otherwise, there will be memory learks.
retain and release function call should be paired in developer's game code.- See:
- cc.Animation#retain
-
retain()
Currently JavaScript Bindings (JSB), in some cases, needs to use retain and release. This is a bug in JSB, and the ugly workaround is to use retain/release. So, these 2 methods were added to be compatible with JSB. This is a hack, and should be removed once JSB fixes the retain/release bug
You will need to retain an object if you created an engine object and haven't added it into the scene graph during the same frame.
Otherwise, JSB's native autorelease pool will consider this object a useless one and release it directly,
when you want to use it later, a "Invalid Native Object" error will be raised.
The retain function can increase a reference count for the native object to avoid it being released,
you need to manually invoke release function when you think this object is no longer needed, otherwise, there will be memory learks.
retain and release function call should be paired in developer's game code.- See:
- cc.Animation#release
-
setDelayPerUnit(delayPerUnit)Sets delay in seconds of the "delay unit"
- Parameters:
- {Number} delayPerUnit
-
setFrames(frames)Sets array of animation frames
- Parameters:
- {Array} frames
-
setLoops(value)Sets how many times the animation is going to loop. 0 means animation is not animated. 1, animation is executed one time, ...
- Parameters:
- {Number} value
-
setRestoreOriginalFrame(restOrigFrame)Sets whether or not it shall restore the original frame when the animation finishes
- Parameters:
- {Boolean} restOrigFrame