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
areaobjectrequiredThe slice's rectangle.
4 fields
xintegerrequiredLeft edge, in pixels from the left of the canvas.
yintegerrequiredTop edge, in pixels from the top of the canvas.
widthintegerrequiredWidth in pixels.
heightintegerrequiredHeight in pixels.
namestringIts name. Leave it out for "Slice N".
nineSliceobjectNine-slice guides: how far in from each edge (all at least 1, leaving a middle).
4 fields
topintegerrequiredPixels from the top edge to the top guide.
rightintegerrequiredPixels from the right edge to the right guide.
bottomintegerrequiredPixels from the bottom edge to the bottom guide.
leftintegerrequiredPixels from the left edge to the left guide.
colorstringThe color its outline shows in, "#RRGGBB", "#RRGGBBAA" or "transparent". Leave it out for the default.
pivotobjectThe 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
xnumberrequiredPixels 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.
ynumberrequiredPixels from the slice's top edge, the same way.
pointsmap of objectsNamed 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
xnumberrequiredPixels 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.
ynumberrequiredPixels from the slice's top edge, the same way.
documentstringWhich 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.expectedRevisionintegerThe 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
documentstringrequiredThe document's id.
revisionintegerrequiredIts revision after the change.
summarystringrequiredWhat changed, in a line.
layerstringThe layer changed or made, if there was one.
changedobjectThe rectangle of pixels that changed, if any did.
4 fields
xintegerrequiredLeft edge, in pixels from the left of the canvas.
yintegerrequiredTop edge, in pixels from the top of the canvas.
widthintegerrequiredWidth in pixels.
heightintegerrequiredHeight in pixels.
pixelsChangedintegerHow many pixels changed.
slicestringThe slice changed or made, if there was one.
effectstringThe effect changed or added, if there was one.
tilestringThe 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
slicestringrequiredWhich slice: its id or exact name.
namestringA new name.
areaobjectA new rectangle.
4 fields
xintegerrequiredLeft edge, in pixels from the left of the canvas.
yintegerrequiredTop edge, in pixels from the top of the canvas.
widthintegerrequiredWidth in pixels.
heightintegerrequiredHeight in pixels.
nineSliceobjectNew nine-slice guides; all 0 to make it a plain slice.
4 fields
topintegerrequiredPixels from the top edge to the top guide.
rightintegerrequiredPixels from the right edge to the right guide.
bottomintegerrequiredPixels from the bottom edge to the bottom guide.
leftintegerrequiredPixels from the left edge to the left guide.
colorstringA new outline color, "#RRGGBB", "#RRGGBBAA" or "transparent".
pivotobjectThe 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
xnumberrequiredPixels 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.
ynumberrequiredPixels from the slice's top edge, the same way.
removePivotbooleanTrue to take the pivot away.
pointsmap of objectsPoints 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
xnumberrequiredPixels 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.
ynumberrequiredPixels from the slice's top edge, the same way.
removePointslist of stringsNames of points to take away, like ["grip"].
documentstringWhich 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.expectedRevisionintegerThe 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
documentstringrequiredThe document's id.
revisionintegerrequiredIts revision after the change.
summarystringrequiredWhat changed, in a line.
layerstringThe layer changed or made, if there was one.
changedobjectThe rectangle of pixels that changed, if any did.
4 fields
xintegerrequiredLeft edge, in pixels from the left of the canvas.
yintegerrequiredTop edge, in pixels from the top of the canvas.
widthintegerrequiredWidth in pixels.
heightintegerrequiredHeight in pixels.
pixelsChangedintegerHow many pixels changed.
slicestringThe slice changed or made, if there was one.
effectstringThe effect changed or added, if there was one.
tilestringThe tile changed or made, if there was one.
delete_sliceDelete a slicedeletes
Removes a slice (the pixels stay). Undo brings it back.
Parameters
slicestringrequiredWhich slice: its id or exact name.
documentstringWhich 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.expectedRevisionintegerThe 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
documentstringrequiredThe document's id.
revisionintegerrequiredIts revision after the change.
summarystringrequiredWhat changed, in a line.
layerstringThe layer changed or made, if there was one.
changedobjectThe rectangle of pixels that changed, if any did.
4 fields
xintegerrequiredLeft edge, in pixels from the left of the canvas.
yintegerrequiredTop edge, in pixels from the top of the canvas.
widthintegerrequiredWidth in pixels.
heightintegerrequiredHeight in pixels.
pixelsChangedintegerHow many pixels changed.
slicestringThe slice changed or made, if there was one.
effectstringThe effect changed or added, if there was one.
tilestringThe tile changed or made, if there was one.