[英]How to animate sprite from plist file
我是Cocos2d的新手,我對Cocos2d-HTML5中的動畫有疑問 。
下面是我的精靈的構造函數。 我已經用TexturePacker生成了plist
文件。 我想播放動畫並無限重復。 我可以通過以下方式創建動畫來播放一次:
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
類的實例。 但是,當我僅傳遞兩個參數時,幀必須是SpriteFrame
類的實例。 如何使用AnimationFrame
並無限重復播放?
好的,我找到了解決方案。 要永遠重復給定的動畫,有一種特殊的動作cc.RepeatForever
。 您只需這樣寫:
var animation = cc.Animation.create(frames, 0.1),
actionToRepeat = cc.Animate.create(animation),
action = cc.RepeatForever.create(actionToRepeat);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.