2014-02-27 2 views
2

나는 간단한 텍스트를 가지고 있으며 텍스트를 클릭 할 때 텍스트를 끝내기를 원합니다. 죄송 새로운Love2d - 텍스트를 클릭 할 수있게 만드는 방법

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

function love.mousepressed(quit) 
    love.event.quit() 
end 
+0

어떻게됩니까? 네가 쥐죽 거리는거야? event.quit()가 실행됩니까? – Schollii

+0

죄송합니다. 나는 어리 석다. – Ross

답변

0
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 
+0

경고! 이는 매 프레임마다'love.mousepressed'를 재정의합니다. 콜백을 일정하게 유지하고 중첩하지 않습니다. – Robin

1

당신은 대신 love.graphics.print를 사용하는 Text 객체를 생성 할 수 있습니다 love2d합니다. 수표에 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 
관련 문제