如何将圆的边缘对齐在一起?
How to align the edge of the circle together?
如何将圆的边缘对齐在一起?盒子的边缘是对齐的,但我的圆圈 circumference/edge 没有对齐,而是它们占据了彼此的空间..
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
-- 确保答案适合屏幕大小,如果需要的话,减少 answerHeight
本地偏移量 = (_W - (howManyAnswers * (answerHeight+answerOffset) - answerOffset)) * 0.5
for i=1, howManyAnswers do
local rect = display.newCircle(quizGroup, offset + (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 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.3
answer.y = rect.y + rect.height * 0.5
answer.anchorX = 0
answer:setFillColor(1)
end
end
结束
尝试
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
如何将圆的边缘对齐在一起?盒子的边缘是对齐的,但我的圆圈 circumference/edge 没有对齐,而是它们占据了彼此的空间..
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
-- 确保答案适合屏幕大小,如果需要的话,减少 answerHeight 本地偏移量 = (_W - (howManyAnswers * (answerHeight+answerOffset) - answerOffset)) * 0.5
for i=1, howManyAnswers do
local rect = display.newCircle(quizGroup, offset + (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 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.3
answer.y = rect.y + rect.height * 0.5
answer.anchorX = 0
answer:setFillColor(1)
end
end
结束
尝试
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