creating a menu for a simple game

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
cj1098
Prole
Posts: 2
Joined: Wed Apr 18, 2012 1:55 am

creating a menu for a simple game

Post by cj1098 »

Hello everyone! I just got started programming games and decided to try out love2d since I'm learning lua. I was wondering if anyone knows any good tutorials for creating just a simple 2-3 button menu when you start up the game.
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: creating a menu for a simple game

Post by Inny »

There's a lot of stuff on the Wiki's Libraries page, https://love2d.org/wiki/Category:Libraries, and I recommend looking through those first before writing your own gui and gamestate management code.
cj1098
Prole
Posts: 2
Joined: Wed Apr 18, 2012 1:55 am

Re: creating a menu for a simple game

Post by cj1098 »

I'm aware of the gamestate libraries that are out there. I've been looking at Gwee in particular but I just can't figure out how to start.. I have a main file where the game resides. All I want to do is make a start up menu. It seems like I have to jump through so many hoops to get that.
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: creating a menu for a simple game

Post by Inny »

If it's a simple "PRESS ENTER TO START" type of thing, then I guess you would do this:

Code: Select all

gamestate = "title"

function love.update(dt)
  if gamestate == "title" then
    if love.keyboard.isDown("return", "enter") then
      gamestate = "play"
    end
  else
    -- do your game logic here
  end
end

function love.draw()
  if gamestate == "title" then
    love.graphics.print( lalawhatever )
  else
    -- draw your game here
  end
end
That's more or less identical to what mari0 does. That game however has more complexity to it, since you can go in and out of menus. It does seem to key off of a single variable to manage it's overall game mode, so that's something you can start with.
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Re: creating a menu for a simple game

Post by Kasperelo »

Not sure what's wrong right now...
Attachments
2dshooter.love
(1.63 KiB) Downloaded 533 times
User avatar
Petunien
Party member
Posts: 191
Joined: Fri Feb 03, 2012 8:02 pm
Location: South Tyrol (Italy)

Re: creating a menu for a simple game

Post by Petunien »

I think you use the wrong key-pressed-detected function.

Try:

Code: Select all

function love.keypressed(key, code)
	if gamestate == "title" then
		if key == "s" then
			gamestate = "playing"
		end
	end
end
So you change the gamestate if a key was pressed. Also, you forgot the "key" argument in your function, so it doesn't know what's to do. :)
"Docendo discimus" - Lucius Annaeus Seneca
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 59 guests