A Layer represents a single layer in a sprite’s layer hierarchy.
Properties
Parent layer group or sprite.
Child layers (only for layer groups).
Position in the layer stack (1-based).
True if this is an image layer.
True if this is a layer group.
True if this is a tilemap layer.
True if this is a transparent layer.
True if this is the background layer.
True if the layer is editable.
True if the layer is visible.
True if continuous layers are enabled.
True if the layer group is collapsed.
True if the layer group is expanded.
True if this is a reference layer.
Array of all cels in this layer.
Layer color in the timeline.
User-defined data string.
User-defined properties table.
Associated tileset (only for tilemap layers).
Unique identifier (UUID).
Methods
layer:cel(frame)
Frame number or Frame object.
Returns the cel at the specified frame.
local cel = layer:cel(1)
if cel then
print("Cel found at frame 1")
end
Examples
Creating and Naming Layers
local sprite = Sprite(32, 32)
local layer1 = sprite:newLayer()
layer1.name = "Character"
layer1.opacity = 200
local layer2 = sprite:newLayer()
layer2.name = "Background"
layer2.blendMode = BlendMode.MULTIPLY
Working with Layer Groups
local sprite = Sprite(64, 64)
local group = sprite:newGroup()
group.name = "Character Parts"
local headLayer = sprite:newLayer()
headLayer.name = "Head"
headLayer.parent = group
local bodyLayer = sprite:newLayer()
bodyLayer.name = "Body"
bodyLayer.parent = group
group.isCollapsed = true
Iterating Through Layers
local sprite = app.sprite
for i, layer in ipairs(sprite.layers) do
print(i, layer.name, layer.opacity)
if layer.isGroup then
for j, child in ipairs(layer.layers) do
print(" ", j, child.name)
end
end
end
Layer Visibility and Properties
local layer = app.layer
layer.isVisible = false
layer.isEditable = true
layer.data = "Custom metadata"
layer.properties = {
author = "John Doe",
version = 1
}
Working with Tilemap Layers
local sprite = Sprite(64, 64)
local tilemapLayer = sprite:newLayer()
if tilemapLayer.isTilemap then
local tileset = tilemapLayer.tileset
print("Tileset:", tileset.name)
print("Grid size:", tileset.grid.tileSize)
end