Problems with clicking menu buttons

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
ccde
Prole
Posts: 15
Joined: Sun Dec 29, 2013 10:47 pm

Problems with clicking menu buttons

Post 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.
Cookie10monster
Prole
Posts: 21
Joined: Wed Apr 15, 2015 10:51 pm

Re: Problems with clicking menu buttons

Post 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:
pielago
Party member
Posts: 142
Joined: Fri Jun 14, 2013 10:41 am

Re: Problems with clicking menu buttons

Post by pielago »

This was giving to me when I started doing menus !
from this I learned a lot,hope you learn as well :)
Attachments
menu.love
(3.74 KiB) Downloaded 176 times
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 217 guests