egret_gif动画(帧动画)

  1. (原文地址)http://edn.egret.com/cn/docs/page/596

  2. 程序使用MovieClip的方法:

  3. 动画监听:
  4. 每次循环完调用:
  5. this.mc1.addEventListener(egret.Event.LOOP_COMPLETE, (e:egret.Event)=>{
  6. console.log(e.type);//输出3次
  7. }, this);
  8. 全部循环完调用:
  9. this.mc1.addEventListener(egret.Event.COMPLETE, (e:egret.Event)=>{
  10. console.log(e.type);//1次
  11. }, this);

源码:
class Ji_Gif extends egret.DisplayObjectContainer {


    private _mcTexture = RES.getRes("ji_png");
    private _mcData = RES.getRes("ji_json");
    private loop = 1;
    private tim;//间隔时间
    private num;//循环次数
    constructor(tim: number,num:number) {
        super();
        this.num=num;
        this.tim = tim;
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
    }


    private onAddToStage(event: egret.Event) {
        let user = JSON.parse(egret.localStorage.getItem("user"));
        this.station();
    }
    //
    private station(): void {
        // let ggAnim = this.parent.getChildByName("ggAnim");
        // if(ggAnim){this.parent.removeChild(ggAnim)};
        var context = this;
        var mcDataFactory = new egret.MovieClipDataFactory(this._mcData, this._mcTexture);
        let role = new egret.MovieClip(mcDataFactory.generateMovieClipData("ji"));
        role.name = "ggAnim";
        role.play(this.num);
        role.x = 0;
        role.y = 0;
        role.scaleX = 2;
        role.scaleY = 2;
        // role.addEventListener(egret.Event.LOOP_COMPLETE, (e: egret.Event) => {


        // }, this);


        role.addEventListener(egret.Event.COMPLETE, (e: egret.Event) => {
            var tim = new egret.Timer(context.tim, 1);
            tim.addEventListener(egret.TimerEvent.TIMER, function () {


                role.play(context.num);
            }, this);
            tim.start();


        }, this);
        this.parent.addChild(role);
    }


    //点击宠物
    private ChongWu(): void {
        // this.parent.parent.addChild(new ChongWu(this));
    }
}



你可能感兴趣的:(egret)