How to combine two images before assigning to a cel - newbie question

I’ve been an Aseprite user since 2018, but I’ve only just started trying my hand at scripting. I’ve dabbled in Lua in the past, and done a fair bit of development, but I’m struggling with the API documentation quite a bit. (For example, it took me about a day to figure out that if I want my image to appear on a layer, it’s not done in in anything to do with “sprite” “image” or “draw” it happens by associating the image with a cel.)

So now I’m having another issue that seems like it should be simple and commonly done, but I can’t seem to find any examples, and my workarounds aren’t working. I want to be able to combine multiple images (or pieces of multiple images specified by rectangular bounds) into a single image, and then assign that combined image to a cel.

I shouldn’t have any pixels of the two images overlapping, but I’m fine with one image overwriting some pixels of another anyway. How can I easily slap one image on top of another like this?

Thank you

More information: It looks like the API suggests that this should be accomplished via drawImage():

However, the following link suggests that doesn’t work: API: Unexpected behavior with Image:drawImage() - #12 by benpm

Finally, I got it working. Here’s what I needed to know: drawImage() completely overwrites pixels regardless of transparency (don’t be fooled by blendMode!), also if you want to construct a blank image, you need only specify width and height of the image, but that width and height are critical, because it’s not going to draw outside of those dimensions.

I was able to convert this:

to this:

with this code snippet:

local layer1 = newSprite:newLayer() = "Frame 2"
local interimImage = Image(sourceImage) -- Only putting this here for the initialization
local sectionWidth = 19 -- Width
local x = 416 -- position of upper left corner of current version
local y = 31
local minHeight = 79
local maxHeight = 151
local outputImage = Image(sectionWidth,maxHeight) --initilization of Image space - must be big enough to hold whole thing

for i = 0, sectionWidth-1 do
    interimImage = Image(sourceImage) --copy the original
    interimImage:resize{size=Size(sectionWidth,minHeight+2*i)} --resize and cut an appropriate slice
    outputImage:drawImage(Image(interimImage, Rectangle{i, 0, i+1, minHeight+2*i}), i, sectionWidth - i) --dump the slice in the appropriate spot, shifted down and right by the right amount
local cel1 = newSprite:newCel(layer1,1,outputImage, Point(x,y-sectionWidth)) --last part only works when slope is 1

This is all because I am making a first-person pixel art dungeon crawler using 2D sprites, and I wanted something to take a single tile and make a first pass at arranging it in all the possible configurations I would want. (I will go and clean them up later)

Anyway, I hope this is helpful for other newbs!

1 Like