在使用Corona SDK的图形2.0时,将基本方向更改代码用于重新布局UI组件。
有人能发现这里的问题吗?当我运行此代码并在纵向和横向之间切换时,它不像预期效果那样工作(矩形的宽度没有随着有效宽度的大小改变而改变)
尝试得到处理自动调整UI元素以支持纵向和横向的基本(简单)概念/方法...
`` ` display.setStatusBar(display.HiddenStatusBar) local WIDTH_PERCENT = 0.8 local myGroup = display.newGroup()
local myRoundedRect = display.newRoundedRect(myGroup,0,0,display.contentWidth * WIDTH_PERCENT,50,25) myRoundedRect.strokeWidth = 3 myRoundedRect:setFillColor(0,1,0) myRoundedRect:setStrokeColor(1,0,0) myRoundedRect.y = 25
local myRoundedRect2 = display.newRoundedRect(myGroup,0,0,display.contentWidth * WIDTH_PERCENT,50,25) myRoundedRect2.strokeWidth = 3 myRoundedRect2:setFillColor(0,0,1) myRoundedRect2:setStrokeColor(1,0,0) myRoundedRect2.y = 75
local function positionItems() myRoundedRect.width = display.contentWidth * WIDTH_PERCENT myRoundedRect2.width = display.contentWidth * WIDTH_PERCENT
myRoundedRect.x = display.contentWidth / 2
myRoundedRect2.x = display.contentWidth / 2
end positionItems()
local function onOrientationChange(event) positionItems() end Runtime:addEventListener(“orientation”,onOrientationChange)
`` `
更新:
似乎存在一些问题,即当已放置一个矩形后,以编程方式设置它的宽度。我认为这是Corona支持的基本操作。因此,我在下面的代码中看到的是:
- 如果最初设置为1000的正方形的宽度,每次切换方向它都会缩小,直到你看不到它
- 如果最初设置为10,确实会出现非常奇怪的模式
- 在重置矩形的大小后,再读取它,它似乎并没有改变值,但仍然无法解释上面两个问题
代码:
`` ` display.setStatusBar(display.HiddenStatusBar)
local WIDTH_PERCENT = 0.5 local INITIAL_BOX_WIDTH = 1000 - 立即通过“positionItems”函数设置的宽度/高度
local myGroup = display.newGroup()
local myRoundedRect = display.newRoundedRect(myGroup,0,0,INITIAL_BOX_WIDTH,INITIAL_BOX_WIDTH,25) myRoundedRect.strokeWidth = 1 myRoundedRect:setFillColor(0,1,0) myRoundedRect:setStrokeColor(1,0,0)
local function positionItems() local displayW,displayH = display.contentWidth,display.contentHeight
myRoundedRect.width = displayW * WIDTH_PERCENT
myRoundedRect.height = displayH * WIDTH_PERCENT
myRoundedRect.x =displayW/2
myRoundedRect.y =displayH/2
print(“将宽度设置为”.. displayW * WIDTH_PERCENT ..“。从Rec读取回来的值为”..myRoundedRect.width)
end positionItems()
local function onOrientationChange(event) positionItems() end Runtime:addEventListener(“orientation”,onOrientationChange)
`` `
配置(下面 - 或什么都没有会导致相同的问题)
`` ` local aspectRatio =display.pixelHeight/display.pixelWidth 申请= { content= { 宽度= aspectRatio > 1.5 and 320 or math.ceil(480 /aspectRatio), 高度= aspectRatio <1.5 and 480 or math.ceil(320 * aspectRatio), 规模= “letterbox”, } }
`` `
建立
`` ` 设置= { 方向= { 默认= “肖像”, 支持= {“肖像”,“横向左”,“横向右”,“倒置肖像” }, },
} `` `
发现问题出在:
a) 在 newRoundedRect 中我使用了一个奇怪的模式,仅涉及到大半径值 b) 看起来 newRoundedRect 中核心缩小的矩形可能是一个bug,当切换为 newRect 后事情开始如预期般工作
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
在
onOrientationChange函数中,传递的事件如下:"portrait" "landscapeLeft" "portraitUpsideDown" "landscapeRight" "faceUp" "faceDown"你需要这样说:
local function onOrientationChange(event) if event.phase=="landscapeLeft" then --在此处编写代码 end end祝你好运,希望这有所帮助。