local sprite = Sprite(width, height)
local sprite = Sprite(width, height, colorMode)
local sprite = Sprite(spec)
local sprite = Sprite(otherSprite)
local sprite = Sprite{ fromFile=filename }
local sprite = Sprite{ fromFile=filename, oneFrame }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().
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.
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.
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 modified = sprite.isModifiedReturns true if the sprite is modified compared to the latest saved state on disk.
Returns the color mode of this sprite.
local spec = sprite.specThe specification for image in this sprite.
for i,frame in ipairs(s.frames) do
-- ...
end
for i = 1,#s.frames do
-- s.frames[i]
endAn array of frames.
An array of palettes. Generally it contains only one
palette (sprite.palettes[1]).
In the future we'll support multiple palettes 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.
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 mark the sprite as saved so closing it doesn't will 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 not parameters are given, the resulting tileset has tile size 16x16 pixels and just 1 tile.
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 sprite content changed because we perform some action on it (also called when we undo/redo those actions). 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.