Hi, so before I dive into learning how to script I would like to know how feasible my idea is.
The reason I need this is long and contrived, so just bear with me because it’s a weird goal. I have an image with two layers and 16 colors in the palette. I want to export it as a single flattened image, but I want the color indices of the second layer to be offset by a number (128).
Can it be done or is this outside the scope of scripting?
OK I gave it a shot and I’m making some progress. The only snag is that I can’t seem to iterate over all pixels in the canvas. I have to go through ‘cels’. Since I’m doing this over a grid of 8x8 tiles I can’t really use cells, it has to be the entire canvas. I could get around that by making a pixel at each corner of the canvas so it identifies the cel with the whole canavas but that’s less than ideal. What am I missing?
edit: maybe I can create a new cel? I tried creating a new image but that didn’t work.
Hi there @Diego_Floor, before you can iterate the canvas content, you have to render the sprite into an image (
Image:drawSprite()), you can do that in this way:
local spr = app.activeSprite
local img = Image(spr.spec) -- create an image to store the canvas content
img:drawSprite(spr, 1) -- render the first frame (1) of the sprite
-- iterate image pixels
for it in img:pixels() do
print("xy " .. it.x .. " " .. it.y .. " = " .. it())
Thank you! I got some help at the Discord channel too. In the end I went with a really dumb code but it works. I used app.usetool (or something like that) and iterated over the pixels while aware of where the activecel is,.