电晕 - 如何将箭头与文本对齐?

时间:2015-03-03 04:06:22

标签: android menu lua alignment corona

我使用Corona sdk创建了一款简单的Android游戏。我几乎已经完成了,现在只是试着打磨。这是我遇到的问题:

enter image description here

这是我游戏的设置页面。玩家可以点击向上/向下箭头来增加/减少游戏属性。我希望箭头与数字对齐。我目前的代码没有考虑到这一点:

local numPlayerstxt = display.newText("Number of players:  "..NUMPLAYERS, w/2,7*h/20,0,0,"Quattrocento-Regular",24)
    numPlayerstxt:setFillColor(0,0,0)
    sceneGroup:insert(numPlayerstxt)

local numMafiatxt = display.newText("Number of Mafia:  "..MAFIA, w/2,12*h/20,0,0,"Quattrocento-Regular",24)
    numMafiatxt:setFillColor(0,0,0)
    sceneGroup:insert(numMafiatxt)

local upTotal = display.newImage( "arrow1.png")
    upTotal:translate(33*w/40, 6*h/20)
    upTotal:scale(0.08, 0.08)
    sceneGroup:insert(upTotal)
    upTotal:addEventListener("tap", increasePlayers)

local downTotal = display.newImage( "arrow1.png")
    downTotal:translate(33*w/40, 8*h/20)
    downTotal:scale(0.08, 0.08)
    downTotal.rotation = 180
    sceneGroup:insert(downTotal)
    downTotal:addEventListener("tap", decreasePlayers)

local upMafia = display.newImage( "arrow1.png")
    upMafia:translate(32*w/40, 11*h/20)
    upMafia:scale(0.08, 0.08)
    sceneGroup:insert(upMafia)
    upMafia:addEventListener("tap", increaseMafia)

local downMafia = display.newImage( "arrow1.png")
    downMafia:translate(32*w/40, 13*h/20)
    downMafia:scale(0.08, 0.08)
    downMafia.rotation = 180
    sceneGroup:insert(downMafia)
    downMafia:addEventListener("tap", decreaseMafia)

如您所见,我的代码目前仅考虑屏幕宽度和高度值,以便合理估计大致位置。当在不同的设备屏幕上尝试应用程序时,这段代码不可避免地会产生任何抛光错误。

有关将箭头与数字对齐的方法的建议吗?例如,在Corona中有没有办法找到textview的终点,并以这种方式对齐它?

感谢阅读。

1 个答案:

答案 0 :(得分:0)

尝试更改每个箭头的anchorX:

-- suppose one of your arrows is upArrow
upArrow.anchorX = 0.4 -- even try each float between 0 - 1

这会将对象的锚点移动到对象的x轴上。