## [SOLVED] Problem with pictured menu

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
ellessaar
Prole
Posts: 3
Joined: Sun Feb 02, 2014 7:36 pm

### [SOLVED] Problem with pictured menu

How can I make menu pictures change? I mean:

I've got a menu (table) and each button in this menu is an image. I want to change image into e.g. a bigger one if the mouse position is on the picture. The question is ...
... how? I made some button_check() function checking the position of mouseX & Y but it doesn't work... Don't know what's wrong.

The code is quite large so I attach it as a .rar to my message (it's all in here, with the pictures).
It's my first post here so, please, forget all my mistakes.
Attachments
My code.rar
Last edited by ellessaar on Mon Feb 03, 2014 1:05 pm, edited 1 time in total.

lachlaan
Prole
Posts: 30
Joined: Sun Jun 30, 2013 7:23 pm

### Re: Problem with pictured menu

Try passing the mouse X and Y coordinates to the check function instead of just using the same name in the separate modules.

Line 43 in menu.lua changes to

Code: Select all

function button_check(mouseX, mouseY)
And line 46 of main.lua changes to

Code: Select all

      button_check(mouseX, mouseY)

ellessaar
Prole
Posts: 3
Joined: Sun Feb 02, 2014 7:36 pm

### Re: Problem with pictured menu

lachlaan wrote:Try passing the mouse X and Y coordinates to the check function instead of just using the same name in the separate modules.

Line 43 in menu.lua changes to

Code: Select all

function button_check(mouseX, mouseY)
And line 46 of main.lua changes to

Code: Select all

      button_check(mouseX, mouseY)
Nothing's happening ;/

Helvecta
Party member
Posts: 167
Joined: Wed Sep 26, 2012 6:35 pm

### Re: Problem with pictured menu

Code: Select all

for i,v in ipairs(button) do
if mouseX > v.x and
mouseX < v.x + v.pic:getWidth() and
mouseY > v.y and
mouseY < v.y + v.pic:getHeight() then
if v.id == "start" then
start = startSet
elseif v.id == "exit" then
exit = exitSet
end
else start = startPic
exit = exitPic
end
end
This loop nearly works correctly; it understands when you're hovering over which image, but what you set is not something that is drawn later on, so it's as if nothing happened. setting exit to exitPic or start to startSet doesn't do anything, because the drawing is relying on the button table. You need to apply changes to v.pic instead, like in the below code:

Code: Select all

function button_check()
for i,v in pairs(button) do
if mouseX > v.x and
mouseX < v.x + v.pic:getWidth() and
mouseY > v.y and
mouseY < v.y + v.pic:getHeight() then
if v.id == "start" then
v.pic = startSet
elseif v.id == "exit" then
v.pic = exitSet
end
else
if v.id == "start" then
v.pic = startPic
elseif v.id == "exit" then
v.pic = exitPic
end
end
end
end
This makes the start button work, but not the exit button. To fix the exit button, go look at your spawn code:

Code: Select all

  button_spawn(320-exit:getWidth()/2,240+hsPic:getHeight(),exit,"quit")
the ID on this button is declared as "quit", but the button_check() function wants the ID to be "exit"! Changing the ID from "quit" to "exit" fixes the problem for the exit button.

I also went ahead and fixed the high score button, even though you haven't put any code in for it yet, check out the attachment for your patched code!

Good luck -- and welcome to the forums!
Attachments
zipperooni.rar
"Bump." -CMFIend420

ellessaar
Prole
Posts: 3
Joined: Sun Feb 02, 2014 7:36 pm

### Re: Problem with pictured menu

Thank you so much, it works fine!

### Who is online

Users browsing this forum: No registered users and 12 guests