我有一个简单的文本,我想让它在我单击该文本时退出。抱歉,是love2d的新手
quit = love.graphics.print( "Quit", 450,375)
function love.mousepressed(quit)
love.event.quit()
end发布于 2014-02-28 00:07:53
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发布于 2016-11-25 03:38:31
您可能希望创建一个Text对象,而不是使用love.graphics.print。然后,您可以在支票中查询其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
endhttps://stackoverflow.com/questions/22070706
复制相似问题