1 搜索了下plist。论坛中内容好像比较少。自己整理了一个,写了个plist动画创建。 适合序列帧动画。
2 我使用的是typescript
代码如下
/** 动画切割名称 */
private animDir=["Down","Left","Right","Up","LeftDown","RightDown","LeftUp","RightUp"];
/** 加载plist资源 */
cc.loader.loadRes ("Role/fyn", cc.SpriteAtlas, (err,atlas)=>{
/** 按名称排序 方便后面切割 */
var fs = atlas.getSpriteFrames();
fs.sort((a,b)=>{
return Number(a.name) - Number(b.name)
})
this.spriteFrames = fs;
/** 初始化clip */
this.init();
})
init(){
var index=0;
this.animDir.forEach(dir=>{
/** 切割图片 */
let sps = this.spriteFrames.slice(index*8, (index+1)*8) as [cc.SpriteFrame];
/** 创建clip */
let clip:cc.AnimationClip = cc.AnimationClip.createWithSpriteFrames(sps,sps.length);
/** 设置clip属性 */
clip.wrapMode = cc.WrapMode.Loop;
clip.name = dir;
/** 将clip添加到animation上 */
this.animation.addClip(clip);
index++;
})
/** 播放设置默认的动画 */
this.animation.play(this.animDir[0]);
}