Page 1 of 1

Problems with clicking menu buttons

Posted: Sat Jun 13, 2015 3:46 pm
by ccde
Hey everybody. I am currently working on adding a menu to my game, however clicking buttons seems to do nothing. It's frustrating me now, because there is no error and I cannot find for the life of me a reason why this wont work. Here is the code.

Code: Select all

function button_click(x, y)
        for i,self in ipairs (button) do
                if x > self.x and
                x < self.x + medium:getWidth(self.text) and
                y > self.y and
                y< self.y + medium:getHeight(self.text) then
                if self.id == "quit" then
                    love.event.quit()
                end
    end
end
end
And my mousepressed function:

Code: Select all

function love.mousepressed(x, y)
    if gamestate == "menu" then
        button_click(x, y)
    end
end
Any ideas? Thanks.

Re: Problems with clicking menu buttons

Posted: Sun Jun 14, 2015 12:19 am
by Cookie10monster
I am no expert on love, but you can try doing this in your update function()

if love.mouse.isDown('l') == true and gamestate == "menu" then --or r
local x = love.mouse.getX()
local y = love.mouse.getY()
button_click(x,y)
end

Sometimes the mousepressed function is weird, hope this helps :awesome:

Re: Problems with clicking menu buttons

Posted: Sun Jun 14, 2015 4:22 am
by pielago
This was giving to me when I started doing menus !
from this I learned a lot,hope you learn as well :)