slicr

A spritesheet utility for webgames

Usage no npm install needed!

<script type="module">
  import slicr from 'https://cdn.skypack.dev/slicr';
</script>

README

slicr

A spritesheet utility for webgames

Installation

$ npm install slicr

Usage

slicr takes two parameters and returns a promise.

slicr(src, options) -> Promise([Image])

src

The src url of the image, or a preloaded image element. Returns a promise either way.

options

{
  width // the width of the individual tile
  height // the height of the individual tile
  slices // the amount of slices, overrules width if width is defined
}

alternatively pass a number representing the amount of slices

Example

var slicr = require('slicr');

slicr('my_tileset.png', 3)
  .then(function(tiles) {
    for (var i = 0; i < tiles.length; i++) {
      document.body.appendChild(tiles[i]);
    }
  });

slicr('my_2d_tileset.png', { width: 16, height: 16 })
  .then(function(tiles) {
    for (var i = 0; i < tiles.length; i++) {
      document.body.appendChild(tiles[i]);
    }
  });

License

The MIT License (MIT)