Love2d - 如何使文本可点击

quit = love.graphics.print("退出", 450, 375)

function love.mousepressed(quit)
  love.event.quit()
end
点赞
用户2584584
用户2584584
# 函数:love.update(dt)
function love.update(dt)
    # 函数:love.mousepressed( x, y)
    function love.mousepressed(x, y)
        # 如果 x 在 440540 之间且 y 在 380410 之间
        if x > 440 and x < 540 and y > 380 and y < 410 then
            # 退出程序
            love.event.quit()
        end
    end
end
2014-02-27 16:07:52
用户336528
用户336528

你可能想创建一个Text对象来替代使用 love.graphics.print。你可以通过查询其 widthheight 来检查它,并使用 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
2016-11-24 19:38:31