Skip to content

Instantly share code, notes, and snippets.

@personalnadir
Last active August 25, 2016 18:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save personalnadir/cfe6105837986291ba65 to your computer and use it in GitHub Desktop.
Save personalnadir/cfe6105837986291ba65 to your computer and use it in GitHub Desktop.
Manages the multiple image sheets and sheet config files generated by TexturePacker's multipack mode. Returns a function that fetches sheet and frameIndex for specified image name.
local M={}
multipackmanager=M
local require=require
local assert=assert
local pairs=pairs
local graphics=graphics
local pcall=pcall
setfenv(1,M)
function init(infodir,sheetdir,infoPrefix,imgPrefix)
local infos={}
local images={}
local sheets={}
if not sheetdir:find("/$") then
sheetdir=sheetdir.."/"
end
local function load()
local fileIndex=#infos
local m=require (infodir .."."..infoPrefix..fileIndex)
assert(m)
local id=fileIndex+1
infos[id]=m
sheets[id]=graphics.newImageSheet(sheetdir..""..imgPrefix..fileIndex..".png",m:getSheet())
for k,v in pairs(m.frameIndex) do
assert(not images[k])
images[k]=id
end
end
while pcall(load) do
end
return function(img)
local id=images[img]
assert(id)
return sheets[id],infos[id]:getFrameIndex(img)
end
end
return M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment