javascript - 如何从 plist 文件制作 Sprite 动画

标签 javascript animation sprite cocos2d-html5

我是 Cocos2d 新手,在 Cocos2d-HTML5 中遇到动画问题。

下面是我的 Sprite 的构造函数。 我生成了plist使用 TexturePacker 文件。 我想播放动画并无限重复。我可以通过以下方式创建动画来播放它一次:

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

但是当我将循环计数作为第三个参数传递时,我收到错误 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);
}

我研究了代码,发现当使用 3 个参数(使用 loops 参数)创建动画时,它需要每个帧都是 AnimationFrame 的实例。类(class)。但是当我只传递 2 个参数时,框架必须是 SpriteFrame 的实例类(class)。如何使用AnimationFrame创建动画并无限重复?

最佳答案

好的,我已经找到解决方案了。要永远重复给定的动画,需要使用特殊类型的操作 cc.RepeatForever。你只需这样写:

var animation = cc.Animation.create(frames, 0.1),
    actionToRepeat = cc.Animate.create(animation),
    action = cc.RepeatForever.create(actionToRepeat);

关于javascript - 如何从 plist 文件制作 Sprite 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22159580/

相关文章:

css - Sprite 滑动门按钮,Firefox 中的额外填充

python - 是否可以在 Pygame 中更改 Sprite 颜色?

javascript - 如何有效地构建这个数组?

javascript - 根据另一个 <select> 的值显示 <select> 中的数据

swift - 如何将物理体添加到 SKAtlasTexture 或通过 Images.xcassets 创建动画?

jquery - setInterval 只运行一次?

c++ - COCOS 2dx无法获取touches?

javascript - 使用 JS 编辑 iframe InnerHTML

php - 如何在另一个php文件中列出一个php文件的值

swift - 将 Subview 置于最前面会弄乱 UIView.animate