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,