2014-02-27 101 views
0

我打印了顯示「是」的文本。我必須按箭頭的形狀。我試圖弄明白,如果我點擊左邊的箭頭說「不」,如果我點擊右邊的箭頭說「是」。love2d - 更新打印文本的文本

fsdefault = "Yes" 
fs = love.graphics.print(fsdefault, 440, 160) 
love.graphics.draw(larrow, 425, 163) 
love.graphics.draw(rarrow, 470, 163) 

function love.update(dt) 
function love.mousepressed(x, y) 
    if x > 424 and x < 435 and y > 161 and y < 172 then 
     fsdefault = "No" 
    end 

    if x > 275 and x < 320 and y > 305 and y < 325 then 
     fsdefault = "Yes" 
    end 
end 
end 
+0

'x> 424和x <335'。選擇一個'x'。它會滿足這兩個條件嗎? – hjpotter92

+0

對不起。它的意思是435.原始文章已被編輯 – Ross

回答

1

如何像:

local fsdefault = "" 
function love.mousepressed(x, y) 
    if x > 424 and x < 435 and y > 161 and y < 172 then 
     fsdefault = "No" 
    end 

    if x > 275 and x < 320 and y > 305 and y < 325 then 
     fsdefault = "Yes" 
    end 
end 

function love.draw() 
    love.graphics.print(fsdefault, 440, 160) 
    love.graphics.draw(larrow, 425, 163) 
    love.graphics.draw(rarrow, 470, 163) 
end 

注意,爲了清楚起見,應只執行內部love.draw屏幕繪圖操作。

另外,儘量避免在love.update內部聲明函數。該代碼片段將使愛情重新定義love.mousepressed您的遊戲的每一幀!