Skip to content

Instantly share code, notes, and snippets.

@gsteigert
Created November 1, 2021 15:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsteigert/b65e1c4c47df2f65d2d7296341e3f5b0 to your computer and use it in GitHub Desktop.
Save gsteigert/b65e1c4c47df2f65d2d7296341e3f5b0 to your computer and use it in GitHub Desktop.
An Aseprite script to ease exporting a bunch of layers and groups into packed sprite sheets (a.k.a. texture atlases).
-- This script will:
-- (1) Flatten each group into a layer;
-- (2) Invoke the 'export sprite sheet' command;
-- (3) Undo the changes.
--
-- v1.0: Initial version.
--
-- Ref: https://github.com/aseprite/aseprite/blob/main/src/app/commands/cmd_export_sprite_sheet.cpp
local spr = app.activeSprite
if not spr then
return app.alert "You should have an sprite opened"
end
local function exportGroups()
app.transaction(function()
for i,layer in ipairs(spr.layers) do
if layer.isGroup then
local name = layer.name
app.range.layers = { layer }
app.command.FlattenLayers(false)
spr.layers[i].name = name
end
end
end)
app.command.ExportSpriteSheet {
splitLayers=true,
}
app.undo()
end
exportGroups()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment