gpt4 book ai didi

lua - 使用 Corona SDK 的不同屏幕尺寸

转载 作者:行者123 更新时间:2023-12-02 08:32:48 30 4
gpt4 key购买 nike

我正在使用 Corona SDK 制作我的第一个 iPhone 游戏,并希望它能在尽可能多的设备(手机 + 平板电脑)上运行。但是我不确定如何处理不同的屏幕尺寸和分辨率。我使用 Corona 模拟器为 iPhone 5 开发了我的游戏,它在该设备上运行良好。当我在 iPhone 4 等低分辨率设备上尝试时,我在每一侧得到 2 个黑色矩形。我尝试创建 2 个不同分辨率的不同背景,并将其添加到我的 config.lua 中:

imageSuffix = {
["@2x"] = 2
}

但这似乎并没有改变任何东西......我不确定我应该在 config.lua 文件的内容中设置什么高度和宽度以及我应该为背景设置什么高度和宽度。如果这些问题很愚蠢,我很抱歉,我才刚刚开始。提前致谢!

最佳答案

听起来您需要全面阅读配置文件和动态缩放。

这个问题有点太宽泛了,我建议你阅读这篇关于 "the ultimate config/modernizing the config" 的文章.

Some screens are wider while others are more narrow. If we take resolution out of the equation, its easier to visualize the screens. Corona makes it easy to take resolution out of the picture using Dynamic Scaling. With Dynamic Scaling, you can use a common set of screen coordinates and Corona will automatically scale the text and graphics for different resolution screens. It can scale upwards or downwards depending on your starting point. It also can substitute higher resolution images when it needs to scale up. This is all managed by a Lua file in your project folder called config.lua.

Since available resolutions vary considerably, it’s helpful to use the same scale for each device. It doesn’t matter if you’re on an iPhone 3GS at 320×480 or a Retina iPad at 1536×2048, the location (0,0) represents the top-left corner and (320,480), in vertical portrait mode, is the bottom-right corner. The screen center is (160,240). Each point, in this case, is one pixel on a lower-resolution device like the 3GS, which has a native screen resolution of 320×480, while each point is four pixels on a Retina iPad. Don’t worry about the math — Corona will handle it for you.

Source: http://coronalabs.com/blog/2012/12/04/the-ultimate-config-lua-file/

这将创建一个充分利用动态缩放和图像缩放的配置文件。

local aspectRatio = display.pixelHeight / display.pixelWidth
application = {
content = {
width = aspectRatio > 1.5 and 320 or math.ceil( 480 / aspectRatio ),
height = aspectRatio < 1.5 and 480 or math.ceil( 320 * aspectRatio ),
scale = "letterBox",
fps = 30,

imageSuffix = {
["@2"] = 1.8,
["@4"] = 3.6,
},
},
}

关于lua - 使用 Corona SDK 的不同屏幕尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25004215/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com