Class cc.Animation

Class Summary
Constructor Attributes Constructor Name and Description
 

A cc.Animation object is used to perform animations on the cc.Sprite objects.

Method Summary

Class Detail

cc.Animation()

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. Example:

//create an animation object
var animation = cc.Animation.create();

//add a sprite frame to this animation
animation.addFrameWithFile("grossini_dance_01.png");

//create an animate with this animation
var action = cc.Animate.create(animation);

//run animate
this._grossini.runAction(action);

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
  • copyWithZone(pZone)
    Parameters:
    {cc.Animation} pZone
  • <static> {cc.Animation} cc.Animation.create(frames, delay, loops)
    Creates an animation.
    //Creates an animation
    var animation1 = cc.Animation.create();
    
    //Create an animation with sprite frames
    var animFrames = [];
    var frame = cache.getSpriteFrame("grossini_dance_01.png");
    animFrames.push(frame);
    var animation2 = cc.Animation.create(animFrames);
    
    //Create an animation with sprite frames and delay
    var animation3 = cc.Animation.create(animFrames, 0.2);
    Parameters:
    {Array} frames
    {Number} delay
    {Number} loops
    Returns:
    {cc.Animation}
  • <static> {cc.Animation} cc.Animation.createWithAnimationFrames(arrayOfAnimationFrameNames, delayPerUnit, loops)
    Creates an animation with an array of cc.AnimationFrame, the delay per units in seconds and and how many times it should be executed.
    Parameters:
    {Array} arrayOfAnimationFrameNames
    {Number} delayPerUnit
    {Number} loops
    Returns:
    {cc.Animation}
  • ctor()
    Constructor
  • {Number} getDelayPerUnit()
    return Delay in seconds of the "delay unit"
    Returns:
    {Number}
  • {Number} getDuration()
    return duration in seconds of the whole animation. It is the result of totalDelayUnits * delayPerUnit
    Returns:
    {Number}
  • {Array} getFrames()
    return array of CCAnimationFrames
    Returns:
    {Array}
  • {Number} getLoops()
    return 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()
    return whether or not it shall restore the original frame when the animation finishes
    Returns:
    {Boolean}
  • {Number} getTotalDelayUnits()
    return total Delay units of the cc.Animation.
    Returns:
    {Number}
  • initWithAnimationFrames(arrayOfAnimationFrames, delayPerUnit, loops)
    Initializes a cc.Animation with cc.AnimationFrame
    Parameters:
    {Array} arrayOfAnimationFrames
    {Number} delayPerUnit
    {Number} loops
  • initWithSpriteFrames(frames, delay)
    Initializes a cc.Animation with frames and a delay between frames
    Parameters:
    {Array} frames
    {Number} delay
  • retain()
    Currently JavaScript Bindigns (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
  • setDelayPerUnit(delayPerUnit)
    set Delay in seconds of the "delay unit"
    Parameters:
    {Number} delayPerUnit
  • setFrames(frames)
    array of CCAnimationFrames setter
    Parameters:
    {Array} frames
  • setLoops(value)
    set 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)
    whether or not it shall restore the original frame when the animation finishes
    Parameters:
    {Boolean} restOrigFrame