如何使精灵适合多个设备的整个屏幕

How to make sprites fit the entire screen of more than one device

我使用 corona 已经有一段时间了,我想知道如何制作精灵(使用纹理打包器)并将其设置为我的应用程序的背景。我还希望它能够适应尽可能多的设备,而不会裁剪掉任何精灵内容。简而言之,我希望 sprite 成为适合整个屏幕的背景,而不会丢失任何 sprite 的内容

希望对您有所帮助:

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