Page 1 of 1

Help, need buttons.

Posted: Mon Aug 26, 2013 3:07 pm
by SniX
All ways i found to create buttons are really messy and ineffective, anyone has any suggestions for main menu buttons?

Re: Help, need buttons.

Posted: Mon Aug 26, 2013 3:10 pm
by Plu
What ways have you found? There's a few libraries on the wiki that're quite good, like Quickie and LoveFrames.

http://www.love2d.org/wiki/Category:Libraries

Re: Help, need buttons.

Posted: Mon Aug 26, 2013 3:14 pm
by SniX
Emm, all i could think of was checking coordinates every time left mouse button has been pressed down, but my menu consists of 6 diffrent choices, that would take a lot of lines of code, so i didnt bother.

Re: Help, need buttons.

Posted: Mon Aug 26, 2013 3:26 pm
by Plu
Checking the mouse coordinates and matching it against any active buttons is pretty much the way to go. But the libraries I mentioned will do it for you.

Re: Help, need buttons.

Posted: Mon Aug 26, 2013 3:42 pm
by Xrott
How about simply putting every button in a table, so you could just iterate over them, like this:

Code: Select all

for i = 1, #buttons do
	if mouseX > buttons[i].x 
	and mouseX < buttons[i].width + buttons[i].x 
	and mouseY > buttons[i].y 
	and mouseY < buttons[i].height + buttons[i].y then
		--your code
	end
end

Re: Help, need buttons.

Posted: Mon Aug 26, 2013 3:54 pm
by Eamonn
Well, check out Sock Munkee dev's video on it, if all you need are simple text buttons, but if you want to make GUI's and some better looking buttons, I'd say look into LöveFrames. It's very easy to use, there is extensive documentation on it and(PLUG!) I make my own tutorial series on LÖVE, and all I have to do is upload those episodes tonight and you could follow those to learn how to make buttons. I would suggest at least checking out some of those libraries: They could save you a lot of headaches.

Re: Help, need buttons.

Posted: Thu Sep 26, 2013 7:43 pm
by SniX
I have a little problem using other peoples codes, i can't really understand what is going on if i haven't made it myself :P

Re: Help, need buttons.

Posted: Thu Sep 26, 2013 7:47 pm
by raidho36
That's a common thing actually. It gets especially bad if people don't format their code properly - don't use tabs *coughjjmafiaecough* or whitespaces *coughmonkeymancough*. And of course if they don't comment obscure algorithms *couggthembothandmanyotherscough* it gets REALLY hard to read others' code.

Re: Help, need buttons.

Posted: Thu Sep 26, 2013 11:38 pm
by davisdude
I think he means more along the lines of something like this:
Since they didn't make it, they don't know how it works. That's at least true for me. :P

Re: Help, need buttons.

Posted: Fri Sep 27, 2013 1:43 am
by iPoisonxL
I always like a thorough explanation of what the code does, so I can be able to write my own version of it.