Egret 利用ImageLoader載入伺服器圖片
阿新 • • 發佈:2019-02-07
let self = this;
let url = "http://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83erb9KD8YAjeDxh2z5yMaVxxtHEaPkkKTfRrDCU1UWbE0RrfE64aHiclZAtB2OkoFWSYBiaymbNpc5aQ/132";
let imgLoader = new egret.ImageLoader();
imgLoader.crossOrigin = "anonymous";// 跨域請求
imgLoader.load(url);// 去除連結中的轉義字元‘\’
imgLoader.once(egret.Event.COMPLETE, function (evt: egret.Event) {
if (evt.currentTarget.data) {
egret.log("載入頭像成功: " + evt.currentTarget.data);
let texture = new egret.Texture();
texture.bitmapData = evt.currentTarget.data;
let bitmap = new egret.Bitmap (texture);
bitmap.x = 200;
bitmap.y = 200;
self.addChild(bitmap);
}
}, this);