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
Asked
Active
Viewed 106 times
1 Answers
0
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

Maicon Feldhaus
- 226
- 2
- 8
-
Thank you for replying. Could you please explain your code so I get what it does ? – Jun 30 '16 at 02:24
-
Load an image (bg.jpg) and set to center position. Change de mode and see the results ('stretch', 'inside' or 'outside'): - stretch: the image will fill the device width/height exactly; - inside: the image will be scaled proportionally to fit inside the device width/height; - outside: the image will be scaled proportionally to completely fill the area, allowing portions of it to exceed the bounds defined by device width/height. – Maicon Feldhaus Jun 30 '16 at 13:32