溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Egret之圖集切割

發(fā)布時(shí)間:2020-07-22 06:19:26 來源:網(wǎng)絡(luò) 閱讀:4474 作者:Aonaufly 欄目:開發(fā)技術(shù)

上一個(gè)核心切割類:

module demo{
    /**
     * 圖集截個(gè)核心工具
     * @author Aonaufly
     */
    export class CutAtlasTools{
        private static _instance : CutAtlasTools = null;
        public static  get Instance() : CutAtlasTools{
            if( !CutAtlasTools._instance ){
                CutAtlasTools._instance = new CutAtlasTools();
            }
            return CutAtlasTools._instance;
        }

        /**
         * 圖集的切圖
         * @param {egret.Bitmap} $bitMap
         * @param {egret.Rectangle} $rec
         * @param {number} $scale
         * @returns {egret.Texture}
         */
        public getSlice2Atlas( $bitMap : egret.Bitmap , $rec : egret.Rectangle , $scale : number = 1.0 ) : egret.Texture{
            let $drawTexture: egret.RenderTexture = new egret.RenderTexture();
            $drawTexture.drawToTexture( $bitMap , $rec , $scale );
            return $drawTexture;
        }
    }
}

測(cè)試 :
一 : 資源準(zhǔn)備
Egret之圖集切割

預(yù)覽資源
①:aaa.png:
Egret之圖集切割
②:aaa.json:

{"file":"aaa.png",
"frames":
{"win.png":{"x":0,"y":0,"w":67,"h":60,"offX":0,"offY":0,"sourceW":67,"sourceH":60},
"up.png":{"x":69,"y":0,"w":44,"h":58,"offX":0,"offY":1,"sourceW":44,"sourceH":60}}}

二 : 加載并使用(測(cè)試)切割工具 (修改Main.ts)

    private _bitMapData : egret.BitmapData = null;
    private _json : JSON = null;
    /**
     * 創(chuàng)建場(chǎng)景界面
     * Create scene interface
     */
    protected startCreateScene(): void {
        let $json_res : string = `resource/assets/aaa.json`;
        let $png_res : string = `resource/assets/aaa.png`;
        demo.LoaderImages4UrlManager.Instance.startLoading(
            $png_res ,
            this.png_loaded.bind(this),
            false
        );
        demo.LoaderTexts4UrlManager.Instance.startLoading(
            $json_res,
            this.json_loaded.bind(this),
            false,
            demo.TyText._TEXT
        );
    }

    private png_loaded( $res : demo.ILoaderImages4CallBack ) : void{
        this._bitMapData = $res._bitmapdata;
        this.checkOver();
    }
    private json_loaded( $res : demo.ILoaderTexts4CallBack ) : void{
        this._json = JSON.parse( <string>$res._content );
        this.checkOver();
    }

    private checkOver() : void{
        if( this._bitMapData && this._json ){
            let $bitmap : egret.Bitmap = new egret.Bitmap( this._bitMapData );
            let $win_config : JSON = this._json["frames"]["win.png"];
            let $rec : egret.Rectangle = new egret.Rectangle(
                +<number>$win_config["x"],
                +<number>$win_config["y"],
                +<number>$win_config["w"],
                +<number>$win_config["h"]
            );
            let $texture : egret.Texture = demo.CutAtlasTools.Instance.getSlice2Atlas( $bitmap , $rec,1.0 );
            let $img : eui.Image = new eui.Image();
            $img.source = $texture;
            this.addChild( $img );
        }
    }

結(jié)果:
Egret之圖集切割

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI