cc.resources.load(path, cc.SpriteAtlas, (err, atlas:cc.SpriteAtlas) => {
if (err){
cc.log(err)
}
this.myres = atlas;
let spriteFrames = atlas.getSpriteFrames();
sprite.spriteFrame = spriteFrames[0];
let obj = [];
// let clips = [];
for (let i = 0; i < spriteFrames.length; i++)
{
let lastIndex = spriteFrames[i].name.lastIndexOf("_");
let str = spriteFrames[i].name.substring(0, lastIndex);
if (obj[str] == null)
{
obj[str] = [];
}
obj[str].push(spriteFrames[i]);
}
let index = 0;
for (let key in obj)
{
let sample = 0;
if (obj[key].length < 5)
sample = 5;
else
sample = 10;
let clip = cc.AnimationClip.createWithSpriteFrames(obj[key], sample);
clip.name = this.actionName[index];
if (index < 5 || index > 9)
{
clip.speed = 1;
clip.wrapMode = cc.WrapMode.Loop;
}
else
{
clip.speed = 1.2;
clip.wrapMode = cc.WrapMode.Normal;
}
// clips.push(clip);
animation.addClip(clip);
index ++;
}
animation.play('stand_down');
this.node.active = true;
this.node.getComponent(MONSTER).player_ani = animation;
});
}
这是一个通过代码把图片写成动画的,有时候会报这个错误,看不明白是什么错误
