Egret之图集切割
admin
2023-02-17 13:20:02
0

上一个核心切割类:

module demo{
    /**
     * 图集截个核心工具
     * @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;
        }
    }
}

测试 :
一 : 资源准备
Egret之图集切割

预览资源
①: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}}}

二 : 加载并使用(测试)切割工具 (修改Main.ts)

    private _bitMapData : egret.BitmapData = null;
    private _json : JSON = null;
    /**
     * 创建场景界面
     * 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( $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(
                +$win_config["x"],
                +$win_config["y"],
                +$win_config["w"],
                +$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 );
        }
    }

结果:
Egret之图集切割

相关内容

热门资讯

美伊维持停火,国际油价回落 新华社纽约5月5日电(记者刘亚南) 由于美国与伊朗停火状态持续,国际原油期货价格5日早盘显著走低后窄...
“AI是否会取代人类工作” 诺... 过去一年,“AI是否会取代人类工作”的讨论持续升温,相关研究报告、行业预判和真实案例不断刷屏,让职场...
每经热评丨豆包收费标志着国产A... 来源:滚动播报 (来源:千龙网) 春节的AI(人工智能)红包大战硝烟尚未散尽,豆包App Store...
北斗导航、无人机“显身手” 春... 眼下,产粮大省黑龙江的春耕工作正有序进行,在位于黑龙江鹤岗的普阳农场,水稻插秧工作从今天起全面启动,...
强词夺理!“中国不应获得最先进... ► 文 观察者网 熊超然 一边想赚中国市场的钱,一边却又“提防”中国科技的崛起,英伟达创始人兼首席执...
苹果iOS 27将允许用户选择... IT之家 5 月 6 日消息,彭博社记者马克 · 古尔曼今日报道称,苹果计划在今年秋季发布的 iOS...
鲁比奥:我们改了措辞,中俄别再... 【文/观察者网 齐倩】当地时间5月5日,美国国务卿鲁比奥在白宫简报会上称,美国提出了新的联合国决议,...
“南鼠北调”为攻击蒋万安?蓝营... 海峡导报综合报道 台北、新北地区近期分别发生“汉坦病毒”死亡及确诊个案,使鼠患问题引发关注。“青鸟”...
巴拿马外长喊话访华团:尊重中国... 【文/观察者网 柳白】据香港英文媒体《南华早报》报道,数名巴拿马议员组成的代表团抵达中国访问之际,巴...
华帝燃气灶自动熄火什么原因 原因:热敏针出现故障,检查灶眼,看中间的火焰能不能烧到探针,烧到探针才能定住火,在点火的时候,长按几...