【发布时间】:2017-09-19 17:54:49
【问题描述】:
所以我尝试了所有似乎无法让图像占据全屏并居中的方法。我附上了图像,以及在电晕上运行时的外观。
我试过这个并得到了我所附的:
local background = display.newImageRect( "bg.png",
display.contentCenterX, display.contentCenterY)
提前感谢您的帮助!
【问题讨论】:
所以我尝试了所有似乎无法让图像占据全屏并居中的方法。我附上了图像,以及在电晕上运行时的外观。
我试过这个并得到了我所附的:
local background = display.newImageRect( "bg.png",
display.contentCenterX, display.contentCenterY)
提前感谢您的帮助!
【问题讨论】:
例如您的config.lua 如下所示
application = {
content = {
width = 640,
height = 960,
scale = "letterBox",
fps = 30,
},
}
然后像下面这样使用以全屏显示图像
local background = display.newImageRect( "bg.png",
640 , 960 )
// then center it like below
background.x = display.contentCenterX
background.y = display.contentCenterY
【讨论】:
根据documentation,你需要传递width和height,而不是x和y。试试这个:
--take screen width and height, so image can take whole screen
local width = display.contentWidth
local height = display.contentHeight
local background = display.newImageRect( "bg.png", width, height)
--setting coordinates to center
background.x = display.contentCenterX
background.y = display.contentCenterY
编辑:如果你使用letterbox缩放模式,你应该调整宽度和高度
width = display.contentWidth - 2 * display.screenOriginX
height = display.contentHeight - 2 * display.screenOriginY
【讨论】:
display.contentWidth。对于letterbox 模式,我使用display.contentWidth - 2 * display.screenOriginX 作为宽度。这同样适用于高度。
如果你想保持图像的纵横比尝试
local _CX = display.contentCenterX
local _CY = display.contentCenterY
local imgW = 440 -- width of image
local imgH = 623-- height of image
local imgR = imgH / imgW
local screenW = display.contentWidth - 2 * display.screenOriginX
local screenH = display.contentHeight - 2 * display.screenOriginY
local screenR = screenH / screenW
local factor = imgR > screenR and screenW / imgW or screenH / imgH
local background = display.newImageRect( 'bg.jpg', imgW * factor, imgH * factor )
background .x, background .y = _CX, _CY
我针对letterbox 模式测试了代码。
来自 Corona 论坛How to make an image full screen?的其他解决方案:
如果你想用图像填充屏幕,最好使 图像大于任何潜在的屏幕纵横比,然后接受一些 当图像超出范围时,某些屏幕上的剪辑量 边缘。
【讨论】: