2016-06-28 75 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你解決了你的問題嗎? –

相關問題