Pass it a table with imageData, it will return a table with quads corresponding do the imagaData received and an image of the atlas to use in SpriteBatches. The table keys used in the quads table will be identical to those used in the passed imageData table. Images are automatically padded to prevent quad bleeding.
local newImageAtlas = require("newImageAtlas")
local atlasQuads,atlasImage = newImageAtlas(imageDataTable)
local spriteBatch = love.graphics.newSpriteBatch(atlasImage)
spriteBatch:add(atlasQuads[key],0,0)
Edit: made it fit the images a little bit more rationally.
Pretty cool, I actually just wrote one of these last week. Where was this lib 2 weeks ago lol. Does it use any kind of sorting algorithm to maximize space usage on the atlas? If so what approach did you use?
pedrosgali wrote: ↑Thu Mar 16, 2017 5:21 pmDoes it use any kind of sorting algorithm to maximize space usage on the atlas? If so what approach did you use?
It sorts all images as rectangles from largest surface area to smallest and adds them to the atlas in that order always next to an already added rectangle. The first free rectangle side it finds is used, it checks sides in order top->left->right>bottom. Atlas width is based on the square root of the total image surface area, height can vary.
Last edited by Azhukar on Thu Mar 16, 2017 8:15 pm, edited 1 time in total.
Any reason why the attached example image has quads that don't have at least a 1px padding?
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
zorg wrote: ↑Thu Mar 16, 2017 6:07 pm
Any reason why the attached example image has quads that don't have at least a 1px padding?
The padding is the same color as the border pixels of the actual image, which is the whole point of the padding - to prevent or rather hide bleeding when scaled/rotated. Since the example is just single color images, it might seem as if there is none.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.