I'm making a clocker video game with lua/love2d. I found out how to detect mouse click in a specific zone. The problem is that when I click, the number increase about 4-5 number even if I click really quickly. I wasn't be able to find the solution. Here's my code :
function love.mousepressed(x, y, button, istouch)
if button == 1 then
mouseClicked.on = true
mouseClicked.x = x
mouseClicked.y = y
end
end
function love.mousereleased(x, y, button, istouch)
if button == 1 then
mouseClicked.on = false
mouseClicked.x = nil
mouseClicked.y = nil
end
end
function Control.Update(ppDt, pIncrement)
local i
for i = 1, #listButtons do
local b = listButtons[i]
--if b.isEnabled == true then -- if the button is showing
if mouseClicked.on == true then -- if the player click
if mouseClicked.x > b.x - tileWidth/2 and
mouseClicked.x < b.x + tileWidth/2 then
if mouseClicked.y > b.y - tileHeight/2 and
mouseClicked.y < b.y + tileHeight/2 then
b.position = "down" -- if the button is clicked, button down
if b.id == 1 then pIncrement = pIncrement + 1 end
end
end
else b.position = "up" end -- if the player doesn t click, button back up
--end
end
return pIncrement
end
I bet the solution is simple but I'm stuck. Is anybody have a clue on that? Thanks.