Egret之异步JSZIP操作

一 ,首先更改Main.ts, 你懂的


    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)

Egret之异步JSZIP操作

①a.txt:
Egret之异步JSZIP操作

三, 加入到资源列表

Egret之异步JSZIP操作

四, 结果

Egret之异步JSZIP操作

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值