TexturePacker Multipack Manager

455
Vote up!

TexturePacker's multipack option created loads of files? Tell this where they are and it gives you a function which fetches the right sheet and frame index for each image without you needing to worry about them

Doc

getSheetAndFrame=multipackmanager.init("dataFileDir", "imageFileDir" , "dataFilePrefix" , "imgFilePrefix")
graphicsSheet, frameIndex = getSheetAndFrame("imageName")

or for convenience:
image=display.newImage(getSheetAndFrame("imageName"))

Example

Assume that you generated some image sheets with the images "bob.png","alice.png" ... "cat.png". Your project structure looks like this:

  • root/
    • img/
      • sheetimg0.png, sheetimg1.png, ... sheetimgn.png <-- All the images with "bob.png" etc.
    • sheets/
      • info0.lua, info1.lua ... infon.lua <-- the Lua files with the frame info

So:

  • Lua files are in the sheets directory, and have the info prefix.
  • Image files are in the img directory with the imagesheet prefix.

Given that you can then write:

local getSheetFrame=multipackmanager.init("sheets","img","info","sheetimg")
local alice=display.newImage(getSheetFrame("alice")) <-- *notice the lack of the .png extension.*
local cat=display.newImage(getSheetFrame("cat"))

Caveat

This assumes you created the files using the Corona SDK (image sheet) option in TexturePacker. The code also assumes that you haven't named your resources such that one set is a prefix of another set. For instance you have one set of files called a0.lua, a1.lua etc. and another set called a_load_of_images0.lua, *a*_load_of_images1.lua etc.

Works with Corona build #: 
2014.2382
Contributor: 
Personalnadir