Developer documentation
Layers and canvas tools
7 tools. Every change a tool makes is one undo step in SpriteGrid.
add_layerAdd a layer
Adds an empty image layer (to draw on), a group (to hold layers), or a linked layer showing another SpriteGrid document (kind "linked" with path: it can't be drawn on, and shows the file as saved, animation and all). Say where with one of above, below or inside; with none, it goes above the selected layer. Returns its id.
Parameters
namestringIts name. Leave it out for "Layer N", "Group N" or the linked file's name.
kindstring"image" (the default), "group" or "linked".
pathstringFor kind "linked": the .spritegrid file to link, as a full path. It can't be this document or one that contains it.
abovestringPut it just above this layer (id or exact name).
belowstringPut it just below this layer.
insidestringPut it at the top of this group.
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_layerChange a layer
Changes a layer's name, visibility, opacity, blend mode, lock or pivot (the point its rotation and scale keys turn and scale it around) — any of them, in one undo step. What you leave out stays as it is.
Parameters
layerstringWhich layer: its id, or its exact name (
describe_documentlists them). Leave it out for the layer selected in SpriteGrid.namestringA new name.
visiblebooleanTrue to show it, false to hide it.
opacitynumber0 (invisible) to 1 (opaque).
blendModestringNormal, Multiply, Screen, Overlay, Add, Subtract, Darken, Lighten... (
describe_documentshows the current one; a wrong name lists them all).lockedbooleanTrue to lock it (it can't be drawn on), false to unlock it.
pivotobjectThe point it turns and scales around, in document pixels: { "x": 64, "y": 64 } is the middle of a 128×128 canvas, where it starts. Put it at a wheel's middle to spin the wheel with rotation keys. Whole numbers are between pixels; add 0.5 for a pixel's middle.
2 fields
xnumberrequiredPixels from the left edge: whole numbers are between pixels, add 0.5 for a pixel's middle.
ynumberrequiredPixels from the 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.
move_layerMove a layer
Moves a layer (a group with everything in it) above or below another, or to the top of a group. Give exactly one of above, below or inside.
Parameters
layerstringWhich layer: its id, or its exact name (
describe_documentlists them). Leave it out for the layer selected in SpriteGrid.abovestringJust above this layer.
belowstringJust below this layer.
insidestringAt the top of this group.
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.
duplicate_layerDuplicate a layer
Copies a layer (a group with everything in it), just above it, and selects the copy. Returns the copy's id.
Parameters
layerstringWhich layer: its id, or its exact name (
describe_documentlists them). Leave it out for the layer selected in SpriteGrid.namestringThe copy's name. Leave it out for "<name> Copy".
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_layerDelete a layerdeletes
Deletes a layer (a group with everything in it). Undo brings it back.
Parameters
layerstringWhich layer: its id, or its exact name (
describe_documentlists them). Leave it out for the layer selected in SpriteGrid.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.
resize_canvasResize the canvas
Changes the canvas size without scaling the art: growing adds transparent pixels, shrinking crops. The anchor says where the art stays.
Parameters
widthintegerrequiredThe new width, 1 to 4096.
heightintegerrequiredThe new height, 1 to 4096.
anchorstringWhere the art stays: top-left (the default), top, top-right, left, center, right, bottom-left, bottom or bottom-right.
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.
set_paletteChange the palette
Changes the document's palette, in this order: replace swaps in a whole new list of colors, remove takes colors out, add puts colors in the first empty cells (a color already there isn't added again).
Parameters
replacelist of stringsThe palette's new colors, in order.
addlist of stringsColors to add.
removelist of stringsColors to take out.
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.