动态加载序列帧动画


动态加载序列帧动画

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
this.roleAP = this.role.getComponent(cc.Animation);
cc.loader.loadRes(url,cc.SpriteAtlas, (err, as) => {
if(err) return;
// 防止重复加载
var clips = this.roleAP.getClips();
for (const clip of clips) {
if(clip.name == cname) return;
}
let name = as.name;
var frames = as.getSpriteFrames();
if(name == cname){
var sprite = this.role.getComponent(cc.Sprite);
sprite.spriteFrame = frames[0];
}
var clip = cc.AnimationClip.createWithSpriteFrames(frames, frames.length);
clip.name = name;
this.roleAP.addClip(clip);
clip.wrapMode = cc.WrapMode.Normal;
this.roleAP.play(name);
});