How to do a menu?

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
Joliplex
Prole
Posts: 7
Joined: Wed Dec 07, 2011 12:17 pm

How to do a menu?

Post 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) :rofl:
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: How to do a menu?

Post 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
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: How to do a menu?

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot] and 6 guests