Trying to copy and paste a sprite to create a pattern with a script

Hi I am trying to copy a 32px * 32px sprite repeatedly onto a 3200px * 3200px canvas but the API is tripping me up.

I can create a canvas with:
local canvasSprite = Sprite(3200,3200)
and load an image with:
local image = Image{ fromFile="../../../../../Pictures/gec.png"}

I also understand how to iterate over a 2D array from various languages although I haven’t tried it in Lua yet I’m sure I’m capable.

But I don’t understand how to draw the image onto the sprite at a specific offset.

Hi @Jenny_Ada! You can draw one image into a new sprite using the Image:drawImage() function, the only problem is finding the image of the sprite first (where gec.png will be pasted), e.g.:

local canvasSprite = Sprite(3200, 3200)
app.command.BackgroundFromLayer() -- just to avoid complications with the cel offset after drawing the image

local image = Image{ fromFile="...." }
canvasSprite.cels[1].image:drawImage(image, x, y)
1 Like

Cool got it working with one of the following file paths but it’s quite late so I’m too tired to check:
(C:\Program Files (x86)\Steam\steamapps\common\Aseprite\gec.png)

local canvasSprite = Sprite(3200, 3200)
local image = Image{fromFile="gec.png"}
local x = 0
local y = 0

Now onto the loops :slight_smile:
Thanks for the help!

1 Like

I seem to be misunderstanding how drawImage() works.

If I try:
local x = 31
local y = 0

Then the 32*32 image only renders as the last vertical strip of the image.

The API reference says that the x and y arguments are position data but it seems to be cropping the image instead?