加载图片对象

class Props extends egret.Bitmap {
     private type:number = 0;
    
     public constructor(x,y,obj) {
        super();
        this.once(egret.Event.ADDED_TO_STAGE,function(){this.init(x,y,obj)},this);
    }
    
    private init(x:number,y:number,obj:any){
        this.type = obj.type;
        this.x = x;
        this.y = y;
        this.texture = RES.getRes("300"+this.type+"_png");     //根据default.res.json文件资源组对应的资源名进行加载

    }

}

在需要new一个Props对象的类里面传入坐标和属性参数,可以添加不同种类的图片对象

private type:number = 0;
private prop;

private CreatePropTimerFile(){
        var propX = this.width*0.1;
        var propY = this.height*0.5;
        this.type = parseInt(Math.random()*3+1+"");
        this.prop = new Props(propX,propY,GameData["prop"+this.type]);
        this.addChild(this.prop);
        this.gameTime.start();
        this.setChildIndex( this.prop, this.numChildren );
        
 }

你可能感兴趣的:(Egret)