1

I'm new to Cocos2d and I have problem with animations in Cocos2d-HTML5.

Below is my sprite's constructor function. I've generated plist file with TexturePacker. I would like to play animation and repeat it infinitely. I was able to play it once by creating animation in following way:

var animation = new cc.Animation(frames, 0.2);

But when I pass loops count as a third parameter I get error Uncaught TypeError: Object #<Class> has no method 'getDelayUnits'

ctor: function (position) {
    this._super();

    var cache = cc.SpriteFrameCache.getInstance();
    cache.addSpriteFrames(s_dogList, s_Dog);

    var frames = [];
    for (var i = 1; i <= this.NUMBER_OF_FRAMES; i++) {
        var spriteFrame = cache.getSpriteFrame('dog' + i + '.png');
        frames.push(spriteFrame);
    };
    this.initWithSpriteFrame(frames[0]);

    var animation = cc.Animation.create(frames, 0.2, 100);
    var animate = cc.Animate.create(animation);
    this.runAction(animate);
}

I've investigated the code and I see that when creating animation with 3 parameters (with loops parameter) it needs each frame to be instance of the AnimationFrame class. But when I pass only 2 parameters, frames have to be instances of the SpriteFrame class. How to creat animation using AnimationFrame and repeat it infinitely?

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Łukasz Jagodziński
  • 3,009
  • 2
  • 25
  • 33

1 Answers1

1

Ok I've found the solution. To repeat given animation forever there is special type of action cc.RepeatForever. You just write like this:

var animation = cc.Animation.create(frames, 0.1),
    actionToRepeat = cc.Animate.create(animation),
    action = cc.RepeatForever.create(actionToRepeat);
Łukasz Jagodziński
  • 3,009
  • 2
  • 25
  • 33