For loop 如何将圆的边对齐在一起?
如何将圆的边对齐在一起?框的边缘对齐,但我的圆周长/边缘不对齐,而是相互占据空间For loop 如何将圆的边对齐在一起?,for-loop,lua,position,coronasdk,shape,For Loop,Lua,Position,Coronasdk,Shape,如何将圆的边对齐在一起?框的边缘对齐,但我的圆周长/边缘不对齐,而是相互占据空间 local areaPadding = 5 local topPadding = 160 local answerOffset = 6 local area = answer_rect.width - (areaPadding*-5) local answerHeight = (area-topPadding-(answerOffset*#q.answers))/#q.ans
local areaPadding = 5
local topPadding = 160
local answerOffset = 6
local area = answer_rect.width - (areaPadding*-5)
local answerHeight = (area-topPadding-(answerOffset*#q.answers))/#q.answers
local textX = numberX + 20
local textW = _W - textX - 24
local y = answer_rect.x + areaPadding + topPadding
local howManyAnswers = #q.answers
--如有必要,请确保答案符合屏幕大小,降低答案高度
本地偏移=(_W-(多少人应答*(应答高度+应答偏移)-应答偏移))*0.5
结束
试试看
local _W = display.contentWidth
local _H = display.contentHeight
local areaPadding = 12
local topPadding = 16
local answerOffset = 30 -- you put in this space labels
local area = answer_rect.height - (areaPadding*2.5)
local howManyAnswers = #q.answers
local textX = numberX + 20
local textW = _W - textX - 24
local answerHeight = (area-topPadding-(answerOffset*#q.answers))/howManyAnswers
local y = answer_rect.x + areaPadding + topPadding
-- make sure answers fit screen size if neccessary decrease answerHeight
local offset = (_W - (howManyAnswers * (answerHeight+answerOffset))) * 0.5
for i=1, howManyAnswers do
local rect = display.newRect(quizGroup, offset + answerOffset +(answerHeight+answerOffset)*(i-1), y, answerHeight, answerHeight)
rect.anchorX, rect.anchorY = 0, 0
rect.id = "answer"
rect.index = i
rect:setFillColor(0.1)
rect:addEventListener("touch", buttonTouched)
local label = display.newText({parent=quizGroup, text=i..".", font=native.systemFont, fontSize=20})
label.x = rect.x - answerOffset * 0.5
label.y = rect.y + 0.5 * rect.height
label:setFillColor(0.4)
local answer = display.newText({parent=quizGroup, text=q.answers[i], width=textW, height=0, font=native.systemFont, fontSize=150})
answer.x = rect.x + rect.width * 0.5
answer.y = rect.y + rect.height * 0.5
answer:setFillColor(1)
end
y是垂直轴,x是水平轴。只需使用x和宽度值,而不是y和高度值。这是简单的数学。。。来吧,我的y被指定为一个局部变量,我已经把它改成了x,但它仍然破坏了应用程序,我认为它是在变量的方程上…我非常感谢rect(shape)但是我的文本答案和文本编号标签没有对齐,因为我忘了放代码块,图像在上面…我添加了必要的代码来正确对齐标签和答案,所以一切都应该正常:)一些元素可能需要更小或更大才能看起来更好。天哪,你一定是上天派来的idurniat lol。。这两个框的位置是正确的,但最后一个框是空的。我试图添加显示的“answer.anchorX=0”,但它不合适。我将增加/减少您的值。非常感谢..您擅长数学..我如何调整矩形形状以适合屏幕边缘?还有,我怎样才能使它循环呢?newCircle()可以工作,但会破坏应用程序。。请参见上图。这取决于你如何处理应用程序中的缩放。您可以在config.lua中找到scale设置,请在Corona上阅读更多有关它的信息。请注意,矩形实际上是正方形,边相等
answerHeight
。圆圈是如何破坏你的应用程序的?
local _W = display.contentWidth
local _H = display.contentHeight
local areaPadding = 12
local topPadding = 16
local answerOffset = 30 -- you put in this space labels
local area = answer_rect.height - (areaPadding*2.5)
local howManyAnswers = #q.answers
local textX = numberX + 20
local textW = _W - textX - 24
local answerHeight = (area-topPadding-(answerOffset*#q.answers))/howManyAnswers
local y = answer_rect.x + areaPadding + topPadding
-- make sure answers fit screen size if neccessary decrease answerHeight
local offset = (_W - (howManyAnswers * (answerHeight+answerOffset))) * 0.5
for i=1, howManyAnswers do
local rect = display.newRect(quizGroup, offset + answerOffset +(answerHeight+answerOffset)*(i-1), y, answerHeight, answerHeight)
rect.anchorX, rect.anchorY = 0, 0
rect.id = "answer"
rect.index = i
rect:setFillColor(0.1)
rect:addEventListener("touch", buttonTouched)
local label = display.newText({parent=quizGroup, text=i..".", font=native.systemFont, fontSize=20})
label.x = rect.x - answerOffset * 0.5
label.y = rect.y + 0.5 * rect.height
label:setFillColor(0.4)
local answer = display.newText({parent=quizGroup, text=q.answers[i], width=textW, height=0, font=native.systemFont, fontSize=150})
answer.x = rect.x + rect.width * 0.5
answer.y = rect.y + rect.height * 0.5
answer:setFillColor(1)
end