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之图集切割

相关内容

热门资讯

单向空间杭州旗舰店8年后谢幕,... 去年12月,单向空间杭州乐堤港店员工回应闭店谣言,称“没有收到任何闭店通知”。不到一年,停止营业的消...
带娃家长刷不到下铺,算法不该把... 据新华社的报道,一位宝妈带4岁娃要从昭通去杭州南,在12306上购票时反复被分到上铺,一天内取消三次...
安徽一高标准农田电机出水异常,... 近日,安徽省淮北市濉溪县百善镇丁楼村村民向《都市现场》爆料称:村里2023年建成的高标准农田配套电机...
河北一演唱会音响“翻车”,人声... 近日,来自北京的庞女士向都市现场记者反映,她7月11日在河北唐山观看“青春超燃巨星演唱会”时遭遇了极...
尺素金声|中国经济“失速论”站... 一季度GDP同比增长5.0%、二季度增长4.3%、上半年增长4.7%,2026年中国经济半年报发布后...
NVIDIA最深的护城河要凉!... 7月24日消息,AMD在Advancing AI预简报会上表示,CUDA已不再是外界想象中的那条护城...
廖杰远:三大智能体协同闭环,A... 中国日报网7月24日电 7月22日,在2026年世界互联网大会数字丝路发展论坛数智健康分论坛上,微医...
AI时代构筑超级底座 维谛技术... 文/本报记者 当前,人工智能产业竞争持续向产业链上游延伸,算力竞争早已不再局限于计算芯片性能比拼。具...
刚签核协议不到24小时,美国突... 美国东部时间7月22日下午,美国宣布与沙特阿拉伯签署了一项民用核能协议。据美国有线电视新闻网(CNN...
中国信通院牵头,数据编织国际标... IT之家 7 月 24 日消息,中国信通院今日发文称,国际电信联盟第 21 研究组(ITU-T SG...