Skip to content

Instantly share code, notes, and snippets.

@RandyGaul
Created January 13, 2021 22:43
Show Gist options
  • Save RandyGaul/d0230568b0340488ba663794d386b3c8 to your computer and use it in GitHub Desktop.
Save RandyGaul/d0230568b0340488ba663794d386b3c8 to your computer and use it in GitHub Desktop.
Aseprite Script for converting a square grid of tiles into individual Aseprite frames
-- Splits a sprite upon a grid into individual frames.
-- This file should go into your Aseprite scripts folder.
-- Aseprite -> File -> Scripts -> Open Scripts Folder
local dialog = Dialog("Split Tiles to Layers")
dialog:label{ id="help", label="", text="Set the width and height to split tiles by:" }
dialog:number{ id="tile_w", label="Tile Width:", text="8", focus=true }
dialog:number{ id="tile_h", label="Tile Height:", text="8" }
dialog:button{ id="ok", text="&OK", focus=true }
dialog:button{ text="&Cancel" }
dialog:show()
local data = dialog.data
if not data.ok then return end
local sprite = app.activeSprite
local w = data.tile_w
local h = data.tile_h
local rows = math.floor(sprite.height / h)
local cols = math.floor(sprite.width / w)
local tiles = Sprite(w, h, sprite.spec.colorMode)
app.activeSprite = sprite
for y = 0, rows - 1 do
for x = 0, cols - 1 do
sprite.selection:select(Rectangle(x * w, y * h, w, h))
app.command.CopyMerged()
app.activeSprite = tiles
app.command.Clear()
tiles.selection:selectAll()
app.command.Paste()
if y < rows - 1 or x < cols - 1 then
app.command.NewFrame()
end
app.activeSprite = sprite
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment