我有一个简单的文本,我希望它在我点击文本时退出。对不起新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