您好,登錄后才能下訂單哦!
上一個核心切割類:
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;
}
}
}
測試 :
一 : 資源準備
預覽資源
①:aaa.png:
②: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( <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 );
}
}
結果:
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。