Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua 使用graphics 2.0在Corona SDK中重新显示UI组件的基本方向更改代码_Lua_Coronasdk - Fatal编程技术网

Lua 使用graphics 2.0在Corona SDK中重新显示UI组件的基本方向更改代码

Lua 使用graphics 2.0在Corona SDK中重新显示UI组件的基本方向更改代码,lua,coronasdk,Lua,Coronasdk,有人能发现这里的问题吗?当我运行此操作并在纵向和横向之间切换时,它不会按预期工作(在更改有效宽度的大小后重新调整矩形的宽度) 尝试了解基本(简单)概念/方法是如何处理自动调整UI元素大小以支持纵向和横向 display.setStatusBar( display.HiddenStatusBar ) local WIDTH_PERCENT = 0.8 local myGroup = display.newGroup() local myRoundedRect = display.newRound

有人能发现这里的问题吗?当我运行此操作并在纵向和横向之间切换时,它不会按预期工作(在更改有效宽度的大小后重新调整矩形的宽度)

尝试了解基本(简单)概念/方法是如何处理自动调整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,你会得到一个非常奇怪的模式
  • 重置矩形的大小,然后将其读回后,它的值似乎没有改变,但这仍然不能解释上述两点
代码:

配置(在下面-或者什么都没有给出相同的问题)


onOrientationChange
函数中,传递的事件如下所示:

"portrait"
"landscapeLeft"
"portraitUpsideDown"
"landscapeRight"
"faceUp"
"faceDown"
你需要这样说:

local function onOrientationChange(event)
  if event.phase=="landscapeLeft" then
  --Do code here
  end
end

祝您好运,希望这有所帮助。

onOrientationChange
函数中,传递的事件如下所示:

"portrait"
"landscapeLeft"
"portraitUpsideDown"
"landscapeRight"
"faceUp"
"faceDown"
你需要这样说:

local function onOrientationChange(event)
  if event.phase=="landscapeLeft" then
  --Do code here
  end
end

祝你好运,希望这会有所帮助。

将问题追踪到:

a) 奇怪的图案就是我在newRoundedRect中使用的大半径值
b) 核心收缩Rect似乎是newRoundedRect的一个缺陷,因为当移动到newRect时,事情就会按照预期开始工作。

跟踪到以下问题:

a) 奇怪的图案就是我在newRoundedRect中使用的大半径值
b) 核心收缩矩形似乎是newRoundedRect的一个缺陷,因为当移动到newRect时,然后开始按预期工作

谢谢-这就是我正在做的-我想把问题缩小到图形2.0问题,在事实发生后设置矩形宽度。。。我会更新帖子,你不明白我的意思。在函数中,每当方向改变时,调用该矩形宽度。这就是你想要的吗?我想是的,但我愿意接受建议。我真的只想支持UI中的方向更改。因此,我的理解是,您必须手动调整UI组件的大小。请再次注意,我在Graphics2.0中工作,并尝试不使用兼容模式。如果我遗漏了一些明显的东西,你会很想知道如何最好地支持方向更改:)我很确定你必须手动重新编码对象的位置。对不起的:(没有简单的解决方法谢谢-这就是我正在做的-我想把问题缩小到Graphics 2.0的问题,在事后设置矩形宽度…我会更新postNo你不明白我的意思。在你的函数中,你在方向改变时调用矩形宽度。这是你想要的吗?我想是的,但是我愿意听取建议。我真的只想支持UI中的方向更改。因此我的理解是,您必须手动调整UI组件的大小。请再次注意,我使用的是Graphics 2.0,并尝试不使用兼容模式。如果我缺少一些明显的内容,我们希望了解如何最好地支持方向更改:)我很确定你必须手动重新编码物体的位置。对不起:(没有简单的方法
local function onOrientationChange(event)
  if event.phase=="landscapeLeft" then
  --Do code here
  end
end