dynamic image selection and Texture Packer

Hi, 

I’m using Texture Packer to provision animated sprites and I’m wondering how to adapt the following code to support dynamic image selection @2x, @4x (i.e. to support Retina displays):

Here I’m passing reference to the specific image sheet definition destined for a specific resolution, so I’m not clear on how to make this code generic - how to specify different pPlayMap for higher resolution graphics?

local bPlayMap = require( "b-play-map" ) local pButton ... local bSheet = graphics.newImageSheet("pictures/title/b-play.png",bPlayMap:getSheet()) pButton = display.newSprite(sceneGroup, bSheet, { time = 1800, loopCount = 0, frames = { bPlayMap:getFrameIndex("frame-1"), bPlayMap:getFrameIndex("frame-2"), } }) ... pButton:play()

b-play-map.lua

-- -- created with TexturePacker (http://www.codeandweb.com/texturepacker) -- local SheetInfo = {} SheetInfo.sheet = { frames = { { x=1, y=1, width=86, height=85, }, { x=89, y=1, width=81, height=81, }, }, sheetContentWidth = 171, sheetContentHeight = 87 } SheetInfo.frameIndex = { ["frame-1"] = 1, ["frame-2"] = 2, } function SheetInfo:getSheet() return self.sheet; end function SheetInfo:getFrameIndex(name) return self.frameIndex[name]; end return SheetInfo

Thanks,

Selection of images is automatic as long as you provide them.

Simply generate the @2x, … sheets using the tool when you generate the 1X sheets.  

Then, include the generated scripts and image sheets in your game.

Finally, set up config.lua with the rules you want to use and you’re done.

You never directly use the @MX images.

https://www.youtube.com/watch?v=062kWJfUOJQ&feature=youtu.be

Thank you for your prompt response, that’s very helpful.

Selection of images is automatic as long as you provide them.

Simply generate the @2x, … sheets using the tool when you generate the 1X sheets.  

Then, include the generated scripts and image sheets in your game.

Finally, set up config.lua with the rules you want to use and you’re done.

You never directly use the @MX images.

https://www.youtube.com/watch?v=062kWJfUOJQ&feature=youtu.be

Thank you for your prompt response, that’s very helpful.