2016-06-28 73 views
0

我一直在与corona几个工作,我想知道如何使精灵(使用纹理打包机),并将其设置为我的应用程序的背景。我也希望它能够适应尽可能多的设备,而不会将任何精灵内容都裁剪掉。总之,我想精灵为背景,而不会丢失任何精灵的内容如何让精灵适合多个设备的整个屏幕

回答

0

我希望这可以帮助您的装修整个屏幕:

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 
+0

感谢您的答复。你能解释一下你的代码,这样我就能知道它的作用了吗? –

+0

加载图像(bg.jpg)并设置到中心位置。更改de模式并查看结果('stretch','inside'或'outside'): - stretch:图像将完全填充设备宽度/高度; - 内部:图像将按比例缩放以适应设备宽度/高度; - 外部:图像将按比例缩放以完全填充区域,允许其部分超出由设备宽度/高度定义的边界。 –

+0

@White_tiger你解决了你的问题吗? –

相关问题