1.0.0 • Published 3 years ago

@solaldr/spritesheet v1.0.0

Weekly downloads
-
License
-
Repository
github
Last release
3 years ago

spritesheet

test build version

Description

This library is an easy and customizable way to generate optimized spritesheet through a CLI.

Features

  • JSON map generation (store all the images coords)
  • Fast images processing using sharp
  • Space optimisation: optimize space in the spritesheet to store the more images possible
  • Auto-resize : if there isn't enough space in the spritesheet the chunk will resize down until fit perfectly in the spritesheet
  • Pass multiple input to get multiples sprites in the same texture
  • (Incomming) Multiple textures generation

Installation

npm i -g @solaldr/spritesheet

CLI

Basic use :

spritesheet --input ./myimagesdir
optiontypedescriptiondefault
--w, --widthnumberWidth of the output spritesheet file2048
--h, --heightnumberHeight of the output spritesheet file2048
--chunk.width, --c.wnumberWidth of a single chunkauto (spread amoung disponible space)
--chunk.height, --c.hnumberHeight of a single chunkauto (spread amoung disponible space)
--flexibilitynumberResize factor of a chunkauto (spread amoung disponible space)
--outputstringOutput name of the spritesheetoutput
--inputstringPath to parent directory of target images
--namestringName of the spritesheet

Docs

--input

The input parameter describle the way images will be inported.

--output

The output parameter describle in which directory the spritesheet will be generated.

--name

The name of the spritesheet {name}.json

--width, --w

Represent the width (in pixels) of the output spritesheet. If width is undefined, width will calculated automatically Notice: A power of two is recommanded

--height, --h

Represent the height(px) of the output spritesheet. If height is undefined, height will be equal to the width value Notice: A power of two is recommanded

--chunk.width, --c.w

Each image passed as an input in the CLI create a single chunk. A chunk is defined by the following properties: width, height, x, y Represent the width of a chunk. If this parameter is undefined, the computed width will be constrained by the spritesheet dimensions. For instance, if a spritesheet has dimensions 2048x2048, However the number of chunks, they will be resized automatically to fit inside this dimensions. See --flexibility option for more informations.

--chunk.height, --c.h

Represent the height of a chunk. See chunk.width behavior

--flexibility

The capacity of a chunk to resize in order to fit inside spritesheet dimensions. The parameter is ranged between 0 and 1. Example: If --flexibility 0.5 a chunk will be able to resize down, up to 50% of his width By default:

  • If chunk.width or chunk.height id defined, flexibility will be equal to 0 The chunks will not resize
  • If neither chunk.width or chunk.height is defined, flexibility will be equal to 1 The chunks will resize to fit inside the spritesheet

How to contribute

Install dependencies

npm install

Install and init commitizen

npm install commitizen -g
commitizen init cz-conventional-changelog --save-dev --save-exact
npm run dev

Commit your work

npm run commit

License

MIT.