local sprite = Sprite(width, height)
local sprite = Sprite(width, height, colorMode)
local sprite = Sprite(spec)
local sprite = Sprite(otherSprite)
local sprite = Sprite{ fromFile=string }
local sprite = Sprite{ fromFile=string, oneFrame=true }Creates a new sprite with the given width and height. The
color mode is optional, RGB
by default.
The spec parameter is an image specification object.
If otherSprite is given (other Sprite object), the sprite is duplicated.
If fromFile is given, it indicates a file name (a string) and it's
like opening a new document with app.open().
When loading from a file, setting oneFrame to true will load with only the first animation frame.
local w = sprite.width
sprite.width = wReturns or changes the sprite width. Use Sprite:resize if you want to change the sprite size resizing layers, images, etc.
local h = sprite.height
sprite.height = hReturns or changes the sprite height. Use Sprite:resize if you want to change the sprite size resizing layers, images, etc.
local rectangle = sprite.boundsReturns the bounds of the sprite as a
rectangle in the position 0,0.
This is like calling Rectangle{ x=0, y=0, width=sprite.width, height=sprite.height }.
local rectangle = sprite.gridBounds
sprite.gridBounds = rectangleGets or sets the bounds of the sprite grid as a rectangle. By default this is 16x16 (with origin in 0,0) but the default value can be changed from Edit > Preferences > Grid.
local size = sprite.pixelRatio
sprite.pixelRatio = sizeGets or sets the pixel ratio of the sprite as a size.
local selection = sprite.selection
sprite.selection = newSelectionGets or sets the active sprite selection. This property is an instance of the Selection class to manipulate the set of selected pixels in the canvas.
Keep in mind that local selection = sprite.selection will be a reference to the Sprite's selection, and will update when the Sprite's selection is changed or removed. To clone the selection, you can do the following instead:
local selection = Selection()
selection:add(sprite.selection)local name = sprite.filename
sprite.filename = newNameGets or sets the name of the file from where this sprite was loaded or saved. Or an empty string if this is a new sprite without an associated file.
local id = sprite.idReturns the id of this sprite, as an integer.
local modified = sprite.isModifiedReturns true if the sprite is modified compared to the latest saved state on disk.
local colorspace = sprite.colorSpace
sprite.colorSpace = colorspaceGets or sets the color space of this sprite. Setting works the same as using Sprite:assignColorSpace().
local colormode = sprite.colormodeReturns the color mode of this sprite.
local spec = sprite.specReturns the specification for image in this sprite.
local undosteps = sprite.undoHistory.undoStepsReturns the amount of undo steps (steps before the current step), as an integer.
local redosteps = sprite.undoHistory.redoStepsReturns the amount of redo steps (steps after the current step), as an integer.
for i,frame in ipairs(s.frames) do
-- ...
end
for i = 1,#s.frames do
-- s.frames[i]
endAn array of frames.
local palette = sprite.palettes[1]An array of palettes. In most cases, it only contains one
palette (sprite.palettes[1]), except in a very specific case.
In the event that two or more indexed numbered
files (eg. spr_01.png, spr_02.png, spr_03.png etc.) are
opened as a sequence,
each frame would have its own palette. This only occurs when there are
at least two different indexed palettes, so the indexed palette for
the spr_01.png frame would have different index-to-color mapping
than the indexed palette for the spr_02.png (same with
spr_03.png), hence the need for three sprite palettes. If two
images/frames have the same indexed palette, they will share (so if
spr_01.png and spr_02.png have the same palette, but spr_03.png
has a different one, there would be 2 sprite palettes).
There is no proper UI to support multiple palettes at the moment, but in a future we want to create an easy way to create color cycling animations.
for i,layer in ipairs(s.layers) do
-- ...
end
for i = 1,#s.layers do
-- s.layers[i]
endAn array of layers.
for i,cel in ipairs(s.cels) do
-- ...
end
for i = 1,#s.cels do
-- s.cels[i]
endAn array of cels.
for i,tag in ipairs(s.tags) do
-- ...
end
for i = 1,#s.tags do
-- s.tags[i]
endAn array of tags.
for i,slice in ipairs(s.slices) do
-- ...
end
for i = 1,#s.slices do
-- s.slices[i]
endAn array of slices.
for i,tileset in ipairs(s.tilesets) do
-- ...
end
for i = 1,#s.tilesets do
-- s.tilesets[i]
endAn array of tilesets.
Returns the background
layer a
layer object or nil if the sprite doesn't contain a
background layer.
local number = sprite.transparentColor
sprite.transparentColor = numberThe transparent color is an intenger that specifies what index (0 by
default) is the transparent color in transparent layers on indexed
sprites.
local color = sprite.color
sprite.color = colorGets or sets the user-defined color of this sprite. This color is used to display the tab in the main window of this sprite.
local data = sprite.data
sprite.data = dataGets or sets the user-defined data related to this sprite (a text string).
Access user-defined and extension-defined properties of this sprite.
sprite:resize(width, height)
sprite:resize(size)Resize the sprite (and all frames/cels) to the given dimensions. See Size class.
sprite:crop(x, y, width, height)
sprite:crop(rectangle)Crops the sprite to the given dimensions. See the Rectangle class.
sprite:saveAs(filename)Saves the sprite to the given file and marks the sprite as saved so closing it won't ask to save changes.
sprite:saveCopyAs(filename)Saves a copy of the sprite in the given file but doesn't change the saved state of the sprite, if the sprite is modified and then try to close it, the user will be asked to save changes.
sprite:close()Closes the sprite. This doesn't ask the user to save changes. If you
want to do the classic File > Close where the user is asking to save
changes, you can use app.command.CloseFile().
sprite:loadPalette(filename)Sets the sprite palette loading it from the given file.
The same can be achieved using Palette{ fromFile }:
sprite:setPalette(Palette{ fromFile=filename })sprite:setPalette(palette)Changes the sprite palette.
local colorSpace = ColorSpace{ sRGB=true }
sprite:assignColorSpace(colorSpace)Assign a new color space to the sprite without modifying the sprite pixels.
local colorSpace = ColorSpace{ sRGB=true }
sprite:convertColorSpace(colorSpace)Converts all the sprite pixels to a new color space so the image looks the same as in the previous color space (all pixels will be adjusted to the new color space).
local layer = sprite:newLayer()Creates a new layer at the top of the layers stack.
local layerGroup = sprite:newGroup()Creates a new empty layer group at the top of the layers stack.
sprite:deleteLayer(layer)
sprite:deleteLayer(layerName)Deletes the given layer or the layer with the given layerName (a string).
local frame = sprite:newFrame(frame)
local frame = sprite:newFrame(frameNumber)Creates a copy of the given frame object or frame number
and returns a Frame that points to the newly created
frame in frameNumber position.
Creates a new empty frame in the given frameNumber (an integer) and
returns the new frame.
sprite:deleteFrame(frame)cel = sprite:newCel(layer, frame)
cel = sprite:newCel(layer, frame, image, position)Creates a new cel in the given layer and frame
number. If the image is not specified, a new image will be
created with the size of the sprite canvas. The position
is a point to locate the image.
sprite:deleteCel(cel)
sprite:deleteCel(layer, frame)Deletes the given cel. If the cel is from a transparent layer, the cel is completely deleted, but if the cel is from a background layer, the cel will be delete with the background color.
local tag = sprite:newTag(fromFrameNumber, toFrameNumber)Creates a new tag in the given frame range and with the given name.
sprite:deleteTag(tag)
sprite:deleteTag(tagName)Deletes the given tag.
local slice = sprite:newSlice()
local slice = sprite:newSlice(Rectangle)Returns a new slice.
sprite:deleteSlice(slice)
sprite:deleteSlice(sliceName)Deletes the given slice.
local tileset = sprite:newTileset()
local tileset = sprite:newTileset(Grid)
local tileset = sprite:newTileset(Rectangle)
local tileset = sprite:newTileset(Grid, numTiles)
local tileset = sprite:newTileset(Rectangle, numTiles)
local tileset = sprite:newTileset(anotherTileset)Returns a new tileset and adds it to the sprite's tilesets.
If no parameters are given, the resulting tileset will have just one empty tile and a tile size equal to the active sprite grid size.
If Grid or Rectangle is specified it is used to set the resulting tileset's origin and tile size.
numTiles specifies the number of tiles we want the tileset to contain initially.
If another tileset is passed as the only parameter, the result is a duplicate of it. Take into consideration that the passed tileset cannot belong to another sprite.
sprite:deleteTileset(tileset)
sprite:deleteTileset(tilesetIndex)Deletes the given tileset from the sprite's tilesets.
local tile = sprite:newTile(tileset [, tileIndex])Inserts an empty tile into the given
tileset
at a given tileIndex. If tileIndex is not provided, the new tile
is added to the end of the tileset. This method generates undo
information, so you could use it as an individual operation or in a
transaction.
local tile = tileset:tile(tileIndex)
Sprite:deleteTile(tile)
Sprite:deleteTile(tileset, tileIndex)Removes a tile from a
tileset. This
method generates undo information, so you could use it as an
individual operation or in a
transaction.
sprite:flatten()Flatten all layers of the sprite into one layer.
It's like calling app.commands.FlattenLayers().
Returns the Events object to associate functions
that can act like listeners of specific Sprite events. E.g.
sprite.events:on('change',
function(ev)
print('The sprite has changed')
end)A special ev argument can be sent to the listener. Which generally
is a table, but it can be nil for older version of Aseprite or
events that don't support it.
Available events for a Sprite:
'change': When the sprite content changes because an action is performed on it (also called when those actions are undone/redone). Since Aseprite v1.2.41, you can accessev.fromUndoproperty which istrueif the change came from a undo/redo/undo history event (and not from a direct user change in the sprite).'filenamechange': When the filename associated to a sprite changes.'layerblendmode': The blend mode of a layer is changed.'layername': The name of a layer is changed.'layeropacity': The opacity of a layer is changed.'layervisibility': The visibility of a layer is changed.
local id = sprite.tileManagementPlugin
sprite.tileManagementPlugin = newIdSpecial property to disable Aseprite tile management UI and use an external plugin to handle tilesets and tilemaps in this sprite.
This property is used by the Attachment-System plugin, but any extension can create a totally customized way to handle tiles (and disable the standard UI to avoid conflicts).
Warning: If a sprite has this property set, another plugin shouldn't change it, because it might break the tilesets/tilemaps structure.