Home

Awesome

spritesmith-engine-spec

Specification for spritesmith engines

In addition to this repo, we offer an integration test suite via spritesmith-engine-test.

Version

This documentation is for version:

2.0.0

Documentation

Terminology

In spritesmith, the following terms and definitions will be used:

Process

When spritesmith is generating a spritesheet, we will perform the following steps:

  1. Process images into metadata (e.g. get size of each image)
  2. Calculate layout based on user preferences (outside of engine)
  3. Create canvas to place images on
  4. Place each image on canvas
  5. Export canvas as an image

Exports

A spritesmith engine returns an Engine constructor function with as its module.exports

new Engine(options)

Constructor for a new engine

Engine.specVersion

String representing current specification version the engine is supporting (e.g. '1.0.0')

engine.createCanvas(width, height)

Function to create a new canvas based on the engine. This should have the function signature (width, height, cb)

Returns:

Note: This method is intentionally synchronous. Please run all asynchronous actions during canvas.export. We suggest saving any critical metadata to canvas and reusing it during canvas.export.

engine.createImages(images, cb)

Function to create images which will later be laid out via a canvas. This should have the function signature (images, cb)

new Canvas(width, height, engine)

Placeholder documentation to suggest how to write a canvas. It's possible to avoid using a constructor but it will lead to more trouble than not.

The following methods are required as part of the returned Canvas object

canvas.addImage(image, x, y)

Function to add an image onto our canvas. This should have the function signature (image, x, y)

Note: This method is intentionally synchronous. Please run all asynchronous actions during canvas.export. We suggest saving any critical metadata to canvas and reusing it during canvas.export.

canvas.export(options)

Function to export canvas as an image. This should have the function signature (options, cb)

Returns:

Discovery

In order to make our engines easily discoverable, please provide a spritesmith-engine keyword. Here's a list of existing spritesmith engines:

https://www.npmjs.com/browse/keyword/spritesmith-engine

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style.

Donating

Support this project and others by twolfson via donations.

http://twolfson.com/support-me

Unlicense

As of Oct 28 2015, Todd Wolfson has released this repository and its contents to the public domain.

It has been released under the UNLICENSE.