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.
[SOLVED] Problem with pictured menu
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[SOLVED] Problem with pictured menu
- Attachments
-
- My code.rar
- (2.73 MiB) Downloaded 123 times
Last edited by ellessaar on Mon Feb 03, 2014 1:05 pm, edited 1 time in total.
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
And line 46 of main.lua changes to
Line 43 in menu.lua changes to
Code: Select all
function button_check(mouseX, mouseY)
Code: Select all
button_check(mouseX, mouseY)
Re: Problem with pictured menu
Nothing's happening ;/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 toAnd line 46 of main.lua changes toCode: Select all
function button_check(mouseX, mouseY)
Code: Select all
button_check(mouseX, mouseY)
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
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
Code: Select all
button_spawn(320-exit:getWidth()/2,240+hsPic:getHeight(),exit,"quit")
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
- (2.73 MiB) Downloaded 127 times
"Bump." -CMFIend420
Re: Problem with pictured menu
Thank you so much, it works fine!
Who is online
Users browsing this forum: Bing [Bot] and 1 guest