[SOLVED] Cels seem to be overwriting each other

I’m trying to write my first Aseprite script. The goal of it is to make my own custom exporter that will export to a particular format that I use in my game. Here’s how I expected this to work:

  1. Create a new, temporary sprite
  2. Go through the original sprite and copy the contents of every frame for every layer to the proper position in the temp sprite
  3. Do some other stuff that’s irrelevant to this convo
  4. Export the temp sprite to a .png
  5. Close the temp sprite

I’m having troubles with #2, though. I can loop through every layer and every frame. That’s all working. I’m also generating the [almost] correct coordinates for where the sprites should be written in the temp sprite. However, when I copy the cels to the new sprite, I can’t get them to copy into the correct position. I also can’t get them to be drawn without overwriting all previous content that I’ve drawn (I’m guessing this has to do with copying transparent pixels from the source). Here’s the script as it stands:

Here are the solutions I’ve tried:

  • Passing no position to the cel or to the drawSprite call. This results in everything being drawn at the same position on the output sprite, but each frame overwrites the last.
  • Passing the x and y from lines 54/55 to the new cel on line 57. This results in nothing being drawn (or possibly being drawn off-canvas, I can’t know for sure).
  • Passing a static position (Point(32, 32)) to the new cel on line 57. This results in everything being drawn at the passed position on the output sprite, but each frame overwrites the last.
  • Passing the x and y from lines 54/55 to the drawSprite call on line 59. This results in nothing being drawn (or possibly being drawn off-canvas, I can’t know for sure).
  • Passing a static position (Point(32, 32)) to the drawSprite call on line 59. This results in everything being drawn at the passed position on the output sprite, but each frame overwrites the last.

At this point, I’m sure I’m doing something wrong with the draw calls. I must need to set some sort of parameter that I’ve missed to get it to not overwrite the previous cels. I must also be doing something wrong with the positions that I’m passing in, though I’m not sure what I could be doing wrong there (I’ve verified that the coords are correct).

Any help would be much appreciated. Also, here’s the source sprite that I’m working with:

I figured it out. The issue was that I was creating a new Cel before each of the draws. Pulling line 57 outside of the for loops fixed it.

2 Likes