Page 1 of 1
How to do a menu?
Posted: Fri Mar 02, 2012 9:19 pm
by Joliplex
Hi guys!
When I get answers to my Time reading questions, I think I am one step away from a simple game. I need a menu.
But how should I do it? When I looked into your source codes, I see you use this "gamestate" thinky. Is this the only way to do a menu and how should I use it? Can someone give me tips?
Thanks (again and again)
Re: How to do a menu?
Posted: Fri Mar 02, 2012 10:40 pm
by veethree
A very simple way of doing gamestates is just having a variable called gamestate or something, then depending on the value of it draw and update different things. I usually just use a string. here's an simple example:
Code: Select all
function love.load()
gamestate = "menu"
end
function love.update(dt)
if gamestate == "menu" then
--Menu stuff here
elseif gamestate == "game" then
--Game stuff here
end
end
function love.draw()
if gamestate == "menu" then
--Menu stuff here
elseif gamestate == "game" then
--Game stuff here
end
end
In the menu you would probably want buttons. You could make it all in löve by using love.graphics.rectangle and love.graphics.print, Or design buttons in photoshop or something. then in love.mousepressed you can check if the mouse is on one of the buttons, and if it is, make something happen. Hope this helped at least a little.
I might make a more complete example actually..check back in a minute. lol
Re: How to do a menu?
Posted: Fri Mar 02, 2012 11:00 pm
by veethree
Here's a very basic button and gamestate code. I would recommend using pictures for buttons as that would likely look better. Also, I do believe there are libraries out there for GUI's and menus. Might wanna look into that.