Листинг программы
/**
* Create Animation from url
*
* @param {array} resources
* @returns {cc.Sprite} instance
*/
createAnimationSprite: function (resources) {
var sprite = new cc.Sprite();
cc.loader.load(resources, function (error, response) {
if (error) {
throw new Error('Load error: ' + error);
}
var frames = [];
frames.length = resources.length;
resources.forEach(function (res, index) {
var spriteFrame = new cc.Sprite(res);
frames[index] = spriteFrame.getSpriteFrame();
});
var animation = new cc.Animation(frames, 0.1);
var runningAction = new cc.RepeatForever(new cc.Animate(animation));
sprite.runAction(runningAction);
});
return sprite;
}
Пример
...
var animSprite = createAnimationSprite(['res/runner0.png', 'res/runner1.png']);
this.addChild(animSprite);
...