Corona SDK中如何动态缩放屏幕实现自适应不同尺寸设备?

2026-03-31 22:391阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计481个文字,预计阅读时间需要2分钟。

Corona SDK中如何动态缩放屏幕实现自适应不同尺寸设备?

我的配置文件用于iPad上网,效果不错。但当我选择屏幕较小的设备时,图像会变形。这是我的config.lua文件中的application部分:

luaapplication={ content={ width=768, aspectRatio=1.5 and 800 or math.ceil(1200) }}

我当前的配置文件是用于ipad视网膜,它工作得很好,但是当我选择屏幕较小的设备时,图像会变形.
这是我目前的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, } } }

我想知道是否有一种方法可以动态设置宽度或高度,而无需为每个单独的设备硬编码这些数字.

我建议你阅读这篇关于 “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.

Corona SDK中如何动态缩放屏幕实现自适应不同尺寸设备?

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: 07001

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, }, }, }

本文共计481个文字,预计阅读时间需要2分钟。

Corona SDK中如何动态缩放屏幕实现自适应不同尺寸设备?

我的配置文件用于iPad上网,效果不错。但当我选择屏幕较小的设备时,图像会变形。这是我的config.lua文件中的application部分:

luaapplication={ content={ width=768, aspectRatio=1.5 and 800 or math.ceil(1200) }}

我当前的配置文件是用于ipad视网膜,它工作得很好,但是当我选择屏幕较小的设备时,图像会变形.
这是我目前的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, } } }

我想知道是否有一种方法可以动态设置宽度或高度,而无需为每个单独的设备硬编码这些数字.

我建议你阅读这篇关于 “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.

Corona SDK中如何动态缩放屏幕实现自适应不同尺寸设备?

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: 07001

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, }, }, }