core-egret.Texture

egret.Texture 使用範例


class Main extends eui.UILayer {

    protected createChildren(): void {
        super.createChildren();
        egret.lifecycle.onPause = () => egret.ticker.pause();
        egret.lifecycle.onResume = () => egret.ticker.resume(); 、
        egret.registerImplementation('eui.IAssetAdapter', new AssetAdapter());
        egret.registerImplementation('eui.IThemeAdapter', new ThemeAdapter());
        this.runGame();
    }

    private async loadResource() {
        let loadingView = this.stage.addChild(new LoadingUI()) as LoadingUI;
        await RES.loadConfig('resource/default.res.json', 'resource/');
        await new Promise(resolve => new eui.Theme('resource/default.thm.json', this.stage).once(eui.UIEvent.COMPLETE, resolve, this));
        await RES.loadGroup('preload', 0, loadingView);
        this.stage.removeChild(loadingView);
    }

    private async runGame() {
        await this.loadResource();
        // --- Edwin 給你最乾淨的程式碼, 從這行以下開始寫喔 ---

        // 方法 1 先 load 點陣圖, 將點陣圖包到材質裡, 將材質帶入 image
        const loader: egret.ImageLoader = new egret.ImageLoader();
        loader.once(egret.Event.COMPLETE, (e) => {
            const texture = new egret.Texture;
            texture.bitmapData = e.target.data;
            this.addChild(new eui.Image(texture));
        }, this);
        const url: string = "resource/assets/Slider/thumb.png";
        loader.load(url);

        // 方法 2 將材質帶入 image, RES.getRes('thumb_png') 就是 egret.Texture
        this.addChild(new eui.Image(RES.getRes('thumb_png'))).y = 50;

        // 方法 3 直接給 image 資源名, 推薦使用
        this.addChild(new eui.Image('thumb_png')).y = 100;

    }

}

spacer

沒有留言:

張貼留言