我有一個簡單的文本,我希望它在我點擊文本時退出。對不起新love2dLove2d - 如何使文本可點擊
quit = love.graphics.print("Quit", 450,375)
function love.mousepressed(quit)
love.event.quit()
end
我有一個簡單的文本,我希望它在我點擊文本時退出。對不起新love2dLove2d - 如何使文本可點擊
quit = love.graphics.print("Quit", 450,375)
function love.mousepressed(quit)
love.event.quit()
end
function love.update(dt)
function love.mousepressed(x, y)
if x > 440 and x < 540 and y > 380 and y < 410 then
love.event.quit()
end
end
end
警告!這重新定義了每一幀「love.mousepressed」。保持回調平穩,不要嵌套它們。 – Robin
您可能需要創建的,而不是使用love.graphics.print
一個Text對象。然後您可以在您的支票中查詢其width和height,並使用love.graphics.draw
進行顯示。代碼可能如下所示:
function love.draw()
love.graphics.draw(quit.text, quit.x, quit.y)
end
function love.load()
local font = love.graphics.getFont()
quit = {}
quit.text = love.graphics.newText(font, "Quit")
quit.x = 450
quit.y = 375
end
function love.mousepressed (x, y, button, istouch)
if x >= quit.x and x <= quit.x + quit.text:getWidth() and
y >= quit.y and y <= quit.y + quit.text:getHeight() then
love.event.quit()
end
end
會發生什麼情況?你的mousepressed被調用了嗎? event.quit()是否執行? – Schollii
對不起,我回答了。我當時很蠢 – Ross