private analyzerImg2Texture: ($buffer: ArrayBuffer) => Promise<egret.Texture> = ($buffer): Promise<egret.Texture> => {
return new Promise<egret.Texture>((resolve, reject): void => {
egret.BitmapData.create("arraybuffer", $buffer, ($data: egret.BitmapData): void => {
let $texture: egret.Texture = new egret.Texture();
$texture._setBitmapData($data);
resolve($texture);
});
});
};
/**
* 创建场景界面
* Create scene interface
*/
protected createGameScene(): void {
JSZip.loadAsync( RES.getRes(`zipdemo_zip`) ).then( $jszip => {
$jszip.file("a.txt").async("text").then( ($str : string) => {
console.log(`获得的数据 : ${$str}`);
} );
$jszip.file("button_down.png").async("arraybuffer").then( ($buffer: ArrayBuffer) => {
this.analyzerImg2Texture( $buffer ).then( $texture => {
let $map: egret.Bitmap = new egret.Bitmap($texture);
this.addChild( $map );
} );
} );
} );
// let sky = this.createBitmapByName("bg_jpg");
// this.addChild(sky);
// let stageW = this.stage.stageWidth;
// let stageH = this.stage.stageHeight;
// sky.width = stageW;
// sky.height = stageH;
//
// let topMask = new egret.Shape();
// topMask.graphics.beginFill(0x000000, 0.5);
// topMask.graphics.drawRect(0, 0, stageW, 172);
// topMask.graphics.endFill();
// topMask.y = 33;
// this.addChild(topMask);
//
// let icon: egret.Bitmap = this.createBitmapByName("egret_icon_png");
// this.addChild(icon);
// icon.x = 26;
// icon.y = 33;
//
// let line = new egret.Shape();
// line.graphics.lineStyle(2, 0xffffff);
// line.graphics.moveTo(0, 0);
// line.graphics.lineTo(0, 117);
// line.graphics.endFill();
// line.x = 172;
// line.y = 61;
// this.addChild(line);
//
//
// let colorLabel = new egret.TextField();
// colorLabel.textColor = 0xffffff;
// colorLabel.width = stageW - 172;
// colorLabel.textAlign = "center";
// colorLabel.text = "Hello Egret";
// colorLabel.size = 24;
// colorLabel.x = 172;
// colorLabel.y = 80;
// this.addChild(colorLabel);
//
// let textfield = new egret.TextField();
// this.addChild(textfield);
// textfield.alpha = 0;
// textfield.width = stageW - 172;
// textfield.textAlign = egret.HorizontalAlign.CENTER;
// textfield.size = 24;
// textfield.textColor = 0xffffff;
// textfield.x = 172;
// textfield.y = 135;
// this.textfield = textfield;
//
// let button = new eui.Button();
// button.label = "Click!";
// button.horizontalCenter = 0;
// button.verticalCenter = 0;
// this.addChild(button);
// button.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onButtonClick, this);
}
二, 加入资源(zip)
①a.txt: