我一直在使用电晕,我想知道如何制作一个精灵(使用纹理打包器)并将其设置为我的应用程序的背景。我还希望它能够适应尽可能多的设备,而不会裁掉任何精灵内容。简而言之,我希望精灵是一个适合整个屏幕的背景而不会丢失任何精灵的内容
答案 0 :(得分: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