Fatih Pense's Blog
Aseprite Get Pixel Coordinates with Lua Script
Thursday, February 16th, 2023
I needed coordinates to use in a game engine, where I will move characters to create a choreography. So I needed a bridge between visual editing and an array of (x,y) coordinates.
I randomly stumbled upon Aseprite scripts, after some research I understood it is possible with Aseprite.
Overall, I’m impressed with scripting capabilities. I’m not an expert on drawing scripting APIs. But, It opened my mind into many posibilities.
The following script gets non-transparent pixel coordinates. Because erasing stuff adds transparent pixels.
File location is not dialog based, you need to hardcode it.
It produces an CSV file.
function saveCoordinates(table1)
local file,err = io.open("C:/Users/fatih/coordinates.txt",'w')
if file then
local content = table.concat(table1, "\n")
file:write(content)
file:close()
else
print("error:", err)
end
end
if app.apiVersion < 1 then
return app.alert("This script requires Aseprite v1.2.10-beta3")
end
local cel = app.activeCel
if not cel then
return app.alert("There is no active image")
end
local img = cel.image:clone()
local rgbaA = app.pixelColor.rgbaA
pixel_table = {}
for it in img:pixels() do
if rgbaA(it()) ~= 0 then
table.insert(pixel_table, it.x .. "," .. it.y )
--table.insert(pixel_table, rgbaA(it()))
end
end
saveCoordinates(pixel_table)
app.refresh()