Before using the OnionRing,Please install the dependencies first!
"@types/node", "@types/pngjs": "^3.3.2" "pngjs": "^3.4.0"
npm install typescript
npm install @types/node
npm install pngjs --save
npm install --save @types/pngjs
After dependencies all installed , you can use download OnionRing.ts and import OnionRing into you project.
import * as OnionRing from "./OnionRing";
// rawTextureMetaInfo["assetPath"] can be the url of any png image ex: C:\test\Sample\background.png
let texture: OnionRing.Texture2D = new OnionRing.Texture2D(
rawTextureMetaInfo["assetPath"]
);
let slicedTexture = OnionRing.TextureSlicer.Slice(texture);
console.log(
"slicedTexture.Boarder.Left:" +
slicedTexture.Boarder.Left +
" slicedTexture.Boarder.Right:" +
" slicedTexture.Boarder.Top:" +
slicedTexture.Boarder.Top +
" slicedTexture.Boarder.Bottom:" +
slicedTexture.Boarder.Bottom
);
And automatic sprite slice!