Home > Article > Web Front-end > Egret creates simple animations
//Simple animation example of Egret
//This animation is a frame animation of a heart floating on a click of a button
1. First, prepare the animation. The animation can be either a gif or a swf
2. Drag the prepared gif or swf into Egret's textureManage tool, and click export to generate two files xx.json and xx.png
3. Add the generated files to the egret project (under the resource directory Create a new xx folder and put the two files generated above)
4. Pack the above two files into the default.res.json file
5. Write the following code where the animation needs to be played
//jsonName Exported json file name
//pngName Exported png file name
//parent Object name to be added for animation
//x Animation x value
//y Animation y Value
private playAction(jsonName:string,pngName:string,parent:any,x:number,y:number): void { var data = RES.getRes(jsonName); var txtr = RES.getRes(pngName); var mcFactory: egret.MovieClipDataFactory = new egret.MovieClipDataFactory(data, txtr); var mc1: egret.MovieClip = new egret.MovieClip(mcFactory.generateMovieClipData("xin")); parent.addChild(mc1); mc1.addEventListener(egret.Event.COMPLETE, (e: egret.Event) => { if (mc1) { mc1.parent.removeChild(mc1); } }, this); mc1.x = x; mc1.y = y; mc1.gotoAndPlay(0, 1); }
The above is the detailed content of Egret creates simple animations. For more information, please follow other related articles on the PHP Chinese website!