2016-11-11 8 views
1

円の端をどのように揃えるには? ..円の端を合わせるにはどうすればいいですか?

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 

ボックスのエッジが整列しているが、私の円の円周/エッジが揃わないが、その代わりに、彼らはお互いのスペースを占有する - 必ず答えにフィット画面サイズを作るneccessary減少が ローカルオフセット=(_WをanswerHeight場合 - (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 

enter image description here

+0

yは横軸X、縦軸を試してみてください。単にy値とheight値の代わりにx値とwidth値を使用します。それは簡単な数学です...来る – Piglet

+0

私のyはローカル変数として割り当てられて、私はすでにxに変更しますが、それでもアプリケーションを台無しにします。私は変数の方程式について考えています... –

答えて

1

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 
+0

Idurniat rectについて多くの感謝私のテキストの答えとテキストの番号のラベルは、私はコードのブロックを置くことを忘れているので、イメージの上にある... –

+0

私はラベルと適切にすべてがうまく動作する必要がありますように答えるために必要なコードを追加:)いくつかの要素は、より良く見えるように小さくする必要があるかもしれません。 – ldurniat

+0

私の善良さは、あなたが天下の笑を送ったにちがいないでしょう。2つの箱には正しい位置がありますが、最後の1つは空です。答えは "answer.anchorX = 0"を追加しようとしましたが、それは適合しません。あなたは非常に多くのことをありがとう。あなたの数学はうまくいきます。 –

関連する問題