I been working with corona for a few and I wanted to know how to make a sprite (using texture packer) and set it as a background of my app. I also want it to fit as many devices as it can without any of the sprite content being cropped out. In short, I want the sprite to be a background fitting the entire screen without losing any of the sprite's content
I hope this help you:
local _W = display.actualContentWidth
local _H = display.actualContentHeight
local bg = display.newImage( 'bg.jpg' )
bg.x, bg.y = display.contentCenterX, display.contentCenterY
local mode = 'inside'
-- the image will fill the device width/height exactly
if mode == 'stretch' then
bg.width, bg.height = _W, _H
-- the image will be scaled proportionally to fit inside the device width/height
elseif mode == 'inside' then
local scale = math.min( _W / bg.width, _H / bg.height )
bg:scale(scale, scale)
-- the image will be scaled proportionally to completely fill the area,
-- allowing portions of it to exceed the bounds defined by device width/height
elseif mode == 'outside' then
local scale = math.max( _W / bg.width, _H / bg.height )
bg:scale(scale, scale)
end