Skip to main content
A Frame represents a single frame in a sprite’s animation timeline.

Properties

sprite
Sprite
Parent sprite.
frameNumber
number
Frame number (1-based index).
duration
number
Frame duration in seconds.
previous
Frame
Previous frame in the timeline.
next
Frame
Next frame in the timeline.

Examples

Creating and Configuring Frames

local sprite = Sprite(32, 32)

-- Add new frames
for i=1,10 do
  local frame = sprite:newFrame()
  frame.duration = 0.1  -- 100ms per frame
end

print("Total frames:", #sprite.frames)

Setting Frame Durations

local sprite = app.sprite

-- Set all frames to same duration
for i, frame in ipairs(sprite.frames) do
  frame.duration = 0.05  -- 50ms
end

-- Set specific frame durations
sprite.frames[1].duration = 0.5   -- First frame holds longer
sprite.frames[#sprite.frames].duration = 1.0  -- Last frame holds longest
local frame = app.frame
print("Current frame:", frame.frameNumber)

if frame.previous then
  print("Previous frame:", frame.previous.frameNumber)
end

if frame.next then
  print("Next frame:", frame.next.frameNumber)
end

Frame Duration Animation

local sprite = app.sprite

-- Create acceleration effect
for i, frame in ipairs(sprite.frames) do
  frame.duration = 0.2 - (i * 0.01)
end

-- Calculate total animation time
local totalTime = 0
for i, frame in ipairs(sprite.frames) do
  totalTime = totalTime + frame.duration
end
print("Total animation time:", totalTime, "seconds")