分享个plist的动画写法。

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]);
    }
1赞

如果人物都是这类序列帧 就不用每次都是做动画编辑了。而且,人物也可以使用同一个prefab

有测过性能问题吗,比如开局加载100个角色,每个角色至少5个方向4个动作,和用动画编辑器比哪个高