将图像按比例缩放以适应 display.contentWidth 和 display.contentHeight。

如何将图像缩放到屏幕尺寸?

我尝试过:

image:scale( display.contentWidth, display.contentHeight )
点赞
用户1682268
用户1682268

你可以使用这个代码来适应你的屏幕

local screen_adjustment = 1
local background = display.newImage("Objects/bg.png", true)
background.xScale = (screen_adjustment  * background.contentWidth)/background.contentWidth
background.yScale = background.xScale
background.x = display.contentWidth / 2
background.y = display.contentHeight / 2

只需要改变 screen_adjustment 的值来适应你的屏幕。

2013-06-21 01:22:12
用户1605727
用户1605727

屏幕比例在 Corona 中是固定的,请查看 build.lua

您可以通过更改图像的宽度和高度来实现此目的(它会拉伸图像)

bg.width = display.contentWidth
bg.height = display.contentHeight
bg.x = display.contentWidth / 2
bg.y = display.contentHeight / 2

您还可以使用图像的 xScale 和 yScale 来实现此目的

注意:如果要保持图像的 1:1 比例,xScale 和 yScale 必须相同

通过这样做,您可以参考 DevfaR 的答案

2013-06-21 01:42:02