完善Corona工程中的config.lua文件
来源:互联网 发布:js在线混淆 编辑:程序博客网 时间:2024/06/03 16:04
翻译自Tutorial: Modernizing the config.lua
注意两个概念:
- 内容区域(Content Area)的尺寸(在config.lua文件中定义的尺寸)
display.contentWidth,display.contentHeight
- 屏幕的尺寸(设备的真实尺寸)
display.pixelWidth,display.pixelHeight
如果将scale
的值设置为letterBox
的话,当内容区域的宽高比例与设备的真实宽高比例相同的时候,便可充满整个屏幕。所以我们希望在config.lua
文件中设置的width
、height
的比例等于设备的宽、高比例。
注意:
坐标原点(0,0)是以内容区域的左上角,而不是屏幕的左上角
所以config.lua
文件内容可以这样设置:
local aspectRatio = display.pixelHeight / display.pixelWidthapplication = { content = { width = aspectRatio > 1.5 and 320 or math.floor( 480 / aspectRatio ), height = aspectRatio < 1.5 and 480 or math.floor( 320 * aspectRatio ), scale = "letterBox", fps = 30, imageSuffix = { ["@2x"] = 1.5, ["@4x"] = 3.0, }, },}
讲解:
我们的目标是将内容区域的宽、高比例设置成与设备的宽、高比相同。
对于基本的320x480设备,我们将内容区域的宽设为320,高设为480。
对于”高”设备,像大都数Android设备、iPhone5s等系列设备,我们固定内容区域的宽为320,而高会自动计算,来确保比例相同。
对于”宽”设备,像iPad等设备,我们固定内容区域的高为480,而宽会自动计算,来确保比例相同。
如今,市场上出现了更高分辨率的设备,这也意味着要支持的小屏设备越来越少。一个便利和现代化的内容区域设置为800×1200
。
local aspectRatio = display.pixelHeight / display.pixelWidthapplication = { content = { width = aspectRatio > 1.5 and 800 or math.floor( 1200 / aspectRatio ), height = aspectRatio < 1.5 and 1200 or math.floor( 800 * aspectRatio ), scale = "letterBox", fps = 30, imageSuffix = { ["@2x"] = 1.3, }, },}
额外补充:
Corona论坛中有一位开发者提供了另一种方案:
local ori_X=display.screenOriginX;local ori_Y=display.screenOriginY;print( ori_X,ori_Y );//屏幕的左上角坐标local width=display.pixelWidth;local height=display.pixelHeight;//设备的宽、高print( width,height );local rect=display.newRect( ori_X, ori_Y, width, height );rect.anchorX=0;rect.anchorY=0;rect:setFillColor( 0,1,1 );
0 0
- 完善Corona工程中的config.lua文件
- Corona的工程配置
- Facebook : Corona中的推测执行
- lua中的读写文件
- Nunit工程读取web.config文件
- CocosIDE工程目录config.json文件说明
- 工程根目录config.json文件说明[官方]
- 干货:pkg-config工具在实际工程中的用法
- VS2012 C# dll工程默认的app.config文件
- Asp.net 中的web.config文件
- 认识asp.net 中的web.config文件
- 浅析Asp.net中的Web.config文件
- 浅析Asp.net中的Web.config文件
- 浅析Asp.net中的Web.config文件
- 关于Web.Config文件中的节配置
- 调用web.config文件中的连接字符串
- 浅析Asp.net中的Web.config文件
- 了解ASP.NET中的web.config文件
- lightOJ 1148 【水题】
- opencv导入android studio
- gluPerspective的牛逼解释
- Ubuntu 软件仓库公钥不可用解决方案
- Access restriction:The type JPEGCodec is not accessible due to restriction on required library
- 完善Corona工程中的config.lua文件
- hdu1561 The more, The Better
- css的link a:hover 必须在 a:link 和 a:visited 之后
- 搞晕我的openGL坐标系
- getContentPane()
- jQuery实战-填写个人详细信息
- sql server 去掉导入csv文件时数据上的引号
- 线索二叉树
- Linux 简单入门