Simple image atlas maker for SpriteBatch

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Simple image atlas maker for SpriteBatch

Post by Azhukar »

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.

Use however you like. Download link.

Code: Select all

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.
Attachments
newImageAtlas.lua
The module itself.
(4.95 KiB) Downloaded 189 times
newImageAtlas.love
Example usage.
(7.27 KiB) Downloaded 128 times
Example image.
Example image.
imageAtlas.png (67.37 KiB) Viewed 4319 times
Last edited by Azhukar on Thu Mar 16, 2017 8:12 pm, edited 4 times in total.
pedrosgali
Party member
Posts: 107
Joined: Wed Oct 15, 2014 5:00 pm
Location: Yorkshire, England

Re: Simple image atlas maker for SpriteBatch

Post by pedrosgali »

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?

Code: Select all

if not wearTheseGlasses() then
  chewing_on_trashcan = true
end
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Simple image atlas maker for SpriteBatch

Post by Azhukar »

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.
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Simple image atlas maker for SpriteBatch

Post by zorg »

Any reason why the attached example image has quads that don't have at least a 1px padding?
Me and my stuff :3True 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.
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Simple image atlas maker for SpriteBatch

Post by Azhukar »

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.
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Simple image atlas maker for SpriteBatch

Post by zorg »

Yeah, that makes sense! :3
Me and my stuff :3True 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests