You should structure you code differently so you can use love.mousereleased callback, but a hacky solution for this is:
Code: Select all
if love.mouse.isDown(1) then
func()
end
To do it somewhat properly you would have love.mousereleased somewhere calling this:
Code: Select all
function love.draw()
--at the end of love.draw()
mouse_has_been_released = false
end
function love.mousereleased(x, y, button)
if button == 1 then
mouse_has_been_released = true
end
end
function thm_imgbtn(x, y, sx, sy, img, hmg, func)
-- Local Vars
local mouseover
local imgw = img:getWidth() * sx -- Button Image
local hmgw = hmg:getWidth() * sx
local imgh = img:getHeight() * sy --Hover Image
local hmgh = hmg.getHeight() * sy
-- Checks if Mouse is over button
if sys.mx > x and sys.mx < (x + imgw) and sys.my > y and sys.my < (y + imgh) then
mouseover = true
else
mouseover = false
end
-- Draw Button
if mouseover == false then
LGR.setColor(255,255,255)
LGR.draw(img, x, y, 0, sx, sy)
else
LGR.setColor(255,255,1)
LGR.draw(hmg, x, y, 0, sx, sy)
end
if mouse_has_been_released and mouseover then func() end
end
But ideally you should use x,y in mousereleased to identify on which button it has been pressed.
This basically sets a global flag for this step and removes it at the end of the step (or at least, it should).
EDIT: make sure you're passing the function, and not it's result
Code: Select all
thm_imgbtn(x, y, sx, sy, img, hmg, func)
instead of
Code: Select all
thm_imgbtn(x, y, sx, sy, img, hmg, func())