如何在Corona SDK中动态缩放屏幕

我的当前配置文件适用于 iPad Retina,并且运行完美,但当我选择一个屏幕更小的设备时,图像会变形。这是我的当前 config.lua:

application = {
    content = {
        width = 768,--aspectRatio > 1.5 and 800 or math.ceil( 1200 / aspectRatio ),
        height = 1024,
        scale = "none",
        fps = 60,
        imageSuffix = {
            ["@2x"] = 1.3,
        }
    }
}

我想知道是否有一种动态设置宽度或高度的方法,而不是为每个设备硬编码这些数字。

点赞
用户2424993
用户2424993

我使用“Letterbox缩放”。

application =
{
    content =
    {
        width = 320,
        height = 480,
        scale = "letterbox",
        xAlign = "center",
        yAlign = "center",
        imageSuffix =
        {
            ["@2"] = 1.8,
            ["@4"] = 3.6,
        },
    },
}

因此,我可以使用display.newImageRect,并为320,480设备分辨率提供图像尺寸。@2和@4图像后缀分别是2倍和4倍的图像。

这是一个极好的文章,可以让你了解Corona缩放功能: http://coronalabs.com/blog/2010/11/20/content-scaling-made-easy/

2014-07-14 09:43:17
用户2260604
用户2260604

我建议你阅读这篇关于"the ultimate config/modernizing the config"的文章。

有些屏幕比其他屏幕更宽,有些则更窄。如果我们将分辨率从方程式中删除,就更容易可视化屏幕。Corona通过动态缩放使得将分辨率从图像中删除变得容易。使用动态缩放,你可以使用一组共同的屏幕坐标,Corona将自动为不同分辨率的屏幕缩放文本和图形。它可以根据你的起点向上或向下缩放。如果需要缩放,则它也可以替换高分辨率图像。这一切都由位于项目文件夹中的Lua文件config.lua管理。

由于可用分辨率差异很大,因此使用相同的比例对每个设备都很有帮助。如果你正在使用具有320×480分辨率的iPhone 3GS或具有1536×2048分辨率的Retina iPad,那么位置(0,0)表示左上角,而(320,480)在垂直竖屏模式下是右下角。屏幕中心是(160,240)。在此情况下,每个点都是低分辨率设备(如3GS)上的一个像素,其原生屏幕分辨率为320×480,而在Retina iPad上每个点则是四个像素。不要担心数学问题 - Corona将为您处理它。

来源: 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 = {
         ["@2x"] = 1.3,
      },
   },
}
2014-07-14 10:38:12