SpriteGrid

Developer documentation

Slices tools

3 tools. Every change a tool makes is one undo step in SpriteGrid.

add_sliceAdd a slice

Marks a rectangle of the canvas as a named slice (exported on its own, in a slice sheet), optionally a nine-slice: its guides split it into corners that keep their size and edges and a middle that stretch. A slice can also have a pivot (where a game turns and places the sprite) and named points (where it attaches things, like "grip" or "muzzle"), both metadata for the slice sheet's .json, never drawn. They're in pixels from the slice's top-left corner, where whole numbers fall between pixels and .5 on a pixel's middle: (0, 0) is the corner, (0.5, 0.5) the middle of its first pixel, (6, 6) the middle of a 12×12 slice, (3, 24) the bottom middle of a 6×24 one. They can be outside the slice. The .json gives a pivot as fractions of the slice's size ({ "x": 0.5, "y": 1 } for that bottom middle) and points in pixels.

Parameters

areaobjectrequired

The slice's rectangle.

4 fields
xintegerrequired

Left edge, in pixels from the left of the canvas.

yintegerrequired

Top edge, in pixels from the top of the canvas.

widthintegerrequired

Width in pixels.

heightintegerrequired

Height in pixels.

namestring

Its name. Leave it out for "Slice N".

nineSliceobject

Nine-slice guides: how far in from each edge (all at least 1, leaving a middle).

4 fields
topintegerrequired

Pixels from the top edge to the top guide.

rightintegerrequired

Pixels from the right edge to the right guide.

bottomintegerrequired

Pixels from the bottom edge to the bottom guide.

leftintegerrequired

Pixels from the left edge to the left guide.

colorstring

The color its outline shows in, "#RRGGBB", "#RRGGBBAA" or "transparent". Leave it out for the default.

pivotobject

The pivot, in whole or half pixels from the slice's top-left corner: { "x": 3, "y": 24 } is the bottom middle of a 6×24 slice, { "x": 6, "y": 6 } the middle of a 12×12 one.

2 fields
xnumberrequired

Pixels from the slice's left edge: whole numbers are between pixels, .5 a pixel's middle. It can be negative, or past the slice's width.

ynumberrequired

Pixels from the slice's top edge, the same way.

pointsmap of objects

Named points, in whole or half pixels from the slice's top-left corner: { "grip": { "x": 3, "y": 12 }, "top": { "x": 3, "y": 1 } }. Names are unique within the slice.

2 fields
xnumberrequired

Pixels from the slice's left edge: whole numbers are between pixels, .5 a pixel's middle. It can be negative, or past the slice's width.

ynumberrequired

Pixels from the slice's top edge, the same way.

documentstring

Which document: its id from get_status (like "doc-1"), its path, or its name. Leave it out for the one you're working on, or the one shown in SpriteGrid before you've worked on one.

expectedRevisioninteger

The document's revision when you looked at it: if the document has changed since (the user edited it, say), nothing is done and you're told so.

Returns
documentstringrequired

The document's id.

revisionintegerrequired

Its revision after the change.

summarystringrequired

What changed, in a line.

layerstring

The layer changed or made, if there was one.

changedobject

The rectangle of pixels that changed, if any did.

4 fields
xintegerrequired

Left edge, in pixels from the left of the canvas.

yintegerrequired

Top edge, in pixels from the top of the canvas.

widthintegerrequired

Width in pixels.

heightintegerrequired

Height in pixels.

pixelsChangedinteger

How many pixels changed.

slicestring

The slice changed or made, if there was one.

effectstring

The effect changed or added, if there was one.

tilestring

The tile changed or made, if there was one.

update_sliceChange a slice

Changes a slice's name, rectangle, nine-slice guides (all 0 removes them), color, pivot or named points — any of them, in one undo step. What you leave out stays as it is. A new rectangle of another size keeps the pivot and points where they are on the canvas, as resizing on the canvas does (so a resize from the left or top changes their numbers); one of the same size moves them with the slice. A slice can also have a pivot (where a game turns and places the sprite) and named points (where it attaches things, like "grip" or "muzzle"), both metadata for the slice sheet's .json, never drawn. They're in pixels from the slice's top-left corner, where whole numbers fall between pixels and .5 on a pixel's middle: (0, 0) is the corner, (0.5, 0.5) the middle of its first pixel, (6, 6) the middle of a 12×12 slice, (3, 24) the bottom middle of a 6×24 one. They can be outside the slice. The .json gives a pivot as fractions of the slice's size ({ "x": 0.5, "y": 1 } for that bottom middle) and points in pixels.

Parameters

slicestringrequired

Which slice: its id or exact name.

namestring

A new name.

areaobject

A new rectangle.

4 fields
xintegerrequired

Left edge, in pixels from the left of the canvas.

yintegerrequired

Top edge, in pixels from the top of the canvas.

widthintegerrequired

Width in pixels.

heightintegerrequired

Height in pixels.

nineSliceobject

New nine-slice guides; all 0 to make it a plain slice.

4 fields
topintegerrequired

Pixels from the top edge to the top guide.

rightintegerrequired

Pixels from the right edge to the right guide.

bottomintegerrequired

Pixels from the bottom edge to the bottom guide.

leftintegerrequired

Pixels from the left edge to the left guide.

colorstring

A new outline color, "#RRGGBB", "#RRGGBBAA" or "transparent".

pivotobject

The pivot, in whole or half pixels from the slice's top-left corner: { "x": 3, "y": 24 } is the bottom middle of a 6×24 slice, { "x": 6, "y": 6 } the middle of a 12×12 one. Measured from the new rectangle, if there's one.

2 fields
xnumberrequired

Pixels from the slice's left edge: whole numbers are between pixels, .5 a pixel's middle. It can be negative, or past the slice's width.

ynumberrequired

Pixels from the slice's top edge, the same way.

removePivotboolean

True to take the pivot away.

pointsmap of objects

Points to add, or to move if the slice has one of that name: { "grip": { "x": 3, "y": 12 }, "top": { "x": 3, "y": 1 } }. The slice's other points stay as they are.

2 fields
xnumberrequired

Pixels from the slice's left edge: whole numbers are between pixels, .5 a pixel's middle. It can be negative, or past the slice's width.

ynumberrequired

Pixels from the slice's top edge, the same way.

removePointslist of strings

Names of points to take away, like ["grip"].

documentstring

Which document: its id from get_status (like "doc-1"), its path, or its name. Leave it out for the one you're working on, or the one shown in SpriteGrid before you've worked on one.

expectedRevisioninteger

The document's revision when you looked at it: if the document has changed since (the user edited it, say), nothing is done and you're told so.

Returns
documentstringrequired

The document's id.

revisionintegerrequired

Its revision after the change.

summarystringrequired

What changed, in a line.

layerstring

The layer changed or made, if there was one.

changedobject

The rectangle of pixels that changed, if any did.

4 fields
xintegerrequired

Left edge, in pixels from the left of the canvas.

yintegerrequired

Top edge, in pixels from the top of the canvas.

widthintegerrequired

Width in pixels.

heightintegerrequired

Height in pixels.

pixelsChangedinteger

How many pixels changed.

slicestring

The slice changed or made, if there was one.

effectstring

The effect changed or added, if there was one.

tilestring

The tile changed or made, if there was one.

delete_sliceDelete a slicedeletes

Removes a slice (the pixels stay). Undo brings it back.

Parameters

slicestringrequired

Which slice: its id or exact name.

documentstring

Which document: its id from get_status (like "doc-1"), its path, or its name. Leave it out for the one you're working on, or the one shown in SpriteGrid before you've worked on one.

expectedRevisioninteger

The document's revision when you looked at it: if the document has changed since (the user edited it, say), nothing is done and you're told so.

Returns
documentstringrequired

The document's id.

revisionintegerrequired

Its revision after the change.

summarystringrequired

What changed, in a line.

layerstring

The layer changed or made, if there was one.

changedobject

The rectangle of pixels that changed, if any did.

4 fields
xintegerrequired

Left edge, in pixels from the left of the canvas.

yintegerrequired

Top edge, in pixels from the top of the canvas.

widthintegerrequired

Width in pixels.

heightintegerrequired

Height in pixels.

pixelsChangedinteger

How many pixels changed.

slicestring

The slice changed or made, if there was one.

effectstring

The effect changed or added, if there was one.

tilestring

The tile changed or made, if there was one.