creating a menu for a simple game
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
creating a menu for a simple game
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.
Re: creating a menu for a simple game
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.
Re: creating a menu for a simple game
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.
Re: creating a menu for a simple game
If it's a simple "PRESS ENTER TO START" type of thing, then I guess you would do this:
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.
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
Re: creating a menu for a simple game
Not sure what's wrong right now...
- Attachments
-
- 2dshooter.love
- (1.63 KiB) Downloaded 533 times
Re: creating a menu for a simple game
I think you use the wrong key-pressed-detected function.
Try:
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.
Try:
Code: Select all
function love.keypressed(key, code)
if gamestate == "title" then
if key == "s" then
gamestate = "playing"
end
end
end
"Docendo discimus" - Lucius Annaeus Seneca
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 59 guests