For what is worth: I just wrote some code to handle this:
Code: Select all
sub sprites_save(fileName as string, sprites() as Fb.Image ptr, w as long, sprSize as long)
dim as long count = ubound(sprites) + 1
dim as long cols = w \ sprSize
dim as long rows = count \ cols + abs(count mod cols > 0)
dim as Fb.Image ptr image = imageCreate(cols * sprSize, rows * sprSize, rgba(0, 0, 0, 0))
dim as long xx = 0, yy = 0
for i as integer = 0 to count - 1
put image, (xx, yy), sprites(i), alpha
xx += sprSize
if (xx >= image->width) then
xx = 0
yy += sprSize
end if
next
savePNG(fileName, image)
imageDestroy(image)
end sub
You just give the desired width of the image and the sprite size (works only for square sprites, naturally), and then it calculates the number of rows automatically to fit every sprite needed:
Naturally, it also adjusts the width of the output buffer (regardless of input), so you always end up with an image that is a multiple of the sprite size (however tall; the same principle applies to columns if you want to specify the height and have the image grow horizontally). A bit late, perhaps, but you might find it useful nonetheless.