此处Egret逐帧动画借助Flash以及Texture Merger工具来生成文件( 1:动画描述文件Json , 动画图集文件 )
创新互联专注于中大型企业的成都网站制作、网站设计和网站改版、网站营销服务,追求商业策划与数据分析、创意艺术与技术开发的融合,累计客户超过千家,服务满意度达97%。帮助广大客户顺利对接上互联网浪潮,准确优选出符合自己需要的互联网运用,我们将一直专注成都品牌网站建设和互联网程序开发,在前进的路上,与客户一起成长!本人以一只飞行的鸟为例
先看Flash , 如下
flash的项目名称为 fly.fla
舞台帧信息 , A 和 B为帧标签
打开texture merger , 选择egret movieclip 。将fly.swf拖入到编辑区 , 取名Bird , 如下:
导出动画文件 , json 和 png图集
为导出文件取名:
我们看看mc_test.json文件如下:
{"mc":{ "fly":{ "frameRate":24, "labels":[ {"name":"A","frame":1,"end":3} ,{"name":"B","frame":4,"end":8} ], "events":[ ], "frames":[ { "res":"3E7A5975", "x":-67, "y":-24 }, { "res":"521E77D1", "x":-67, "y":-21 }, { "res":"4A0EE357", "x":-73, "y":-24 }, { "res":"34630D9E", "x":-71, "y":-36 }, { "res":"175B90A8", "x":-74, "y":-29 }, { "res":"4BC2B418", "x":-74, "y":-44 }, { "res":"A49D29C2", "x":-76, "y":-40 }, { "res":"B1A21F34", "x":-73, "y":-19 } ] }}, "res":{ "34630D9E":{"x":1,"y":1,"w":136,"h":77}, "521E77D1":{"x":280,"y":62,"w":122,"h":61}, "3E7A5975":{"x":142,"y":121,"w":123,"h":56}, "4A0EE357":{"x":139,"y":1,"w":136,"h":59}, "175B90A8":{"x":139,"y":62,"w":139,"h":57}, "B1A21F34":{"x":267,"y":125,"w":139,"h":41}, "A49D29C2":{"x":1,"y":121,"w":139,"h":53}, "4BC2B418":{"x":277,"y":1,"w":136,"h":59} }}
解释如下:
在项目中实现此MC的播放
核心代码:
protected childrenCreated():void{ super.childrenCreated(); this.txt_name.text = "Snow"; this.img_dragon.source = RES.getRes("egret_icon_png"); //this.playDragonEff(); this.ayncLoad2Mc("mc_test_json"); } private ayncLoad2Mc( resname : string) : void{ var self = this; RES.getResAsync(resname, function(data: any,key: string): void { if(key == "mc_test_json") { self.ayncLoad2Mc("mc_test_png"); } else if(key == "mc_test_png") { this.playMC(); } }, this); } private playMC() : void{ var data2mc = RES.getRes("mc_test_json"); var texture2mc = RES.getRes("mc_test_png"); let mcFactory : egret.MovieClipDataFactory = new egret.MovieClipDataFactory(data2mc,texture2mc); let mc:egret.MovieClip = new egret.MovieClip(mcFactory.generateMovieClipData("fly")); mc.gotoAndPlay("A",-1);//"A" : 标签 -1 : 循环播放 this.addChild(mc); mc.x = 200; mc.y = 400; }
结果:
解释:
帧事件标签
mc.addEventListener(egret.MovieClipEvent.FRAME_LABEL,(e:egret.MovieClipEvent)=>{ console.log(e.type,e.frameLabel,mc.currentFrame);},this);
如 :
{"mc":{ "Battle_start":{ "frameRate":12, "labels":[ ], "events":[ {"name":"@enemy","frame":8} ], "frames":[
那么 : e.frameLabel == "@enemy"
注意 : {"name":"@enemy","frame":8}可以手写加上
每一轮循环播放完毕触发
mc.addEventListener(egret.Event.LOOP_COMPLETE, (e:egret.Event)=>{ console.log(e.type);}, this);
完全播放完毕触发
mc.addEventListener(egret.Event.COMPLETE, (e:egret.Event)=>{ console.log(e.type);}, this);
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。