ShelfPack

index.mjs

Create a new ShelfPack bin allocator.

Uses the Shelf Best Height Fit algorithm from http://clb.demon.fi/files/RectangleBinPack.pdf

new ShelfPack(w: number, h: number, options: Object?)
Parameters
w (number = 64) Initial width of the sprite
h (number = 64) Initial width of the sprite
options (Object?)
Name Description
options.autoResize boolean (default false) If true , the sprite will automatically grow
Example
var sprite = new ShelfPack(64, 64, { autoResize: false });
Instance Members
pack(bins, options?)
packOne(w, h, id?)
shrink()
getBin(id)
ref(bin)
unref(bin)
clear()
resize(w, h)

Create a new Bin object.

new Bin(id: (number | string), x: number, y: number, w: number, h: number, maxw: number?, maxh: number?)
Parameters
id ((number | string)) Unique id of the bin
x (number) Left coordinate of the bin
y (number) Top coordinate of the bin
w (number) Width of the bin
h (number) Height of the bin
maxw (number?) Max width of the bin (defaults to w if not provided)
maxh (number?) Max height of the bin (defaults to h if not provided)
Example
var bin = new Bin('a', 0, 0, 12, 16);