Create a new ShelfPack bin allocator.
Uses the Shelf Best Height Fit algorithm from http://clb.demon.fi/files/RectangleBinPack.pdf
64)
:
Initial width of the sprite
64)
:
Initial width of the sprite
false)
If true, the sprite will automatically grow
var sprite = new ShelfPack(64, 64, { autoResize: false });
#clear
Clear the sprite.
Clear the sprite.
sprite.clear();
#pack(bins, [options])
Batch pack multiple bins into the sprite.
Batch pack multiple bins into the sprite.
Array of requested bins - each object should have width, height (or w, h) properties
false)
If true, the supplied bin objects will be updated inplace with x and y properties
Array
:
Array of allocated bins - each bin is an object with x, y, w, h properties
var bins = [
{ id: 'a', width: 12, height: 12 },
{ id: 'b', width: 12, height: 16 },
{ id: 'c', width: 12, height: 24 }
];
var results = sprite.pack(bins, { inPlace: false });
#resize(w, h)
Resize the sprite. The resize will fail if the requested dimensions are smaller than the current sprite dimensions.
Resize the sprite. The resize will fail if the requested dimensions are smaller than the current sprite dimensions.
boolean
:
true if resize succeeded, false if failed
sprite.resize(256, 256);