Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions Export Sprite Sheet - Tags On Seperate Rows.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
-- Export all tags into a single PNG
-- Each tag occupies one row

local src = app.activeSprite
if not src then
print("No active sprite")
return
end

local path, title = src.filename:match("^(.+[/\\])(.-).([^.]*)$")
if not path then
path = ""
title = src.filename
end

-- Find longest animation
local maxFrames = 0
for _, tag in ipairs(src.tags) do
local count = tag.toFrame.frameNumber - tag.fromFrame.frameNumber + 1
maxFrames = math.max(maxFrames, count)
end

local imageWidth = src.width
local imageHeigt = src.height
local numRows = #src.tags
local out = Sprite(imageWidth * maxFrames, imageHeigt * numRows, src.colorMode)

function GenerateSpriteSheet()
for row, tag in ipairs(src.tags) do
local startFrame = tag.fromFrame.frameNumber
local endFrame = tag.toFrame.frameNumber
local col = 0

for frameIndex = startFrame, endFrame do
local cel = src.cels[frameIndex]

if cel then
local img = cel.image
local dstX = col * imageWidth
local dstY = (row - 1) * imageHeigt

out.cels[1].image:drawImage(img, Point(dstX, dstY))
end
col = col + 1
end
end
end

app.transaction(GenerateSpriteSheet)

local filename = path .. title .. "-full.png"

out:saveCopyAs(filename)

print("Exported: " .. filename)

out:close()