我是 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/