No description, website, or topics provided.
Lua
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
menu
LICENSE.md
README.md
bg1.png
bg2.png
bg3.png
conf.lua
license.txt
main.lua
screenshot.png

README.md

Mouse, keyboard input. See main.lua for example usage. Press R for bg roate.

Simple Setup

  1. Require the "lovemenu" in your game before love.load function.
menu = require("path-to-menu.lua") --no need to put the .lua extension

function love.load()

end
  1. Then inside the love.load function:
menu = require("libraries/menu")
function love.load()
	menu:toggle()
	menu_view = {} --table to hold all the menu views
	
	--THIS IS THE MAIN MENU
	menu_view[1] = {
		title = "Main Menu", --Title to show
		desc = "This is the main menu.", --You could put empty string if you dont want to show anything
		{t = "Start", cb = "sg"}, --t is the text, cb is callback
		{t = "Settings", cb = "st"}, --keep the cb variable simple
		{t = "Quit", cb = "quit"} -- you can add as many as you want.
	}
end

Now, that is all for the "main menu".

  1. Now, let us add the other views (start,settings, quit, etc)
menu = require("libraries/menu")

function love.load()
	--MAIN MENU CODE ABOVE

	--View for the Settings
	menu_view[2] = {
		title = "Settings",
		desc = "This is for customizing the default settings",
		{t = "Sound", cb = "sound"},
		{t = "Controls", cb = "cntrl"},
		--MAKE MORE IF YOU LIKE
		{t = "Return", cb "mainmenu"}
	}

	--Go and make the rest of the other views
end
  1. After the main menu views setup
menu = require("libraries/menu")
function love.load()
	-- GAME VIEWS SETUP ABOVE
	menu:load(menu_view) 
	menu.bg = love.graphics.newImage("path-to-image") -- for the bg
end

function love.update(dt)
	menu:update(dt)
end

function love.draw()
	menu:draw() 
end
  1. Now let us setup a simple callbacks system (cb)
function menu:callback(cb)
	if cb == "sg" then --the start game callback we used above
		--code to start the game
	elseif cb == "st" then --settings
		menu:setstate(2) --go to the "menu_view[2]"
	elseif cb == "quit" then --quit
		menu:setstate(3)
	end --etc
end
  1. Last is the keyboard function
function love.keypressed(key)
	menu:keypressed(key)
end

Additional configurations

If you want to change the font for the title, desc, and menu. Do

menu = require("libraries/menu")

function love.load()
	--before setting up the views:
	menu.font_title = love.graphics.newFont("path-to-font.ttf, 64) --default is Orbitron with size of 64
	menu.font_desc = love.graphics.newFont("path-to-font.ttf, 22) --default is League_Gothic-webfont with size of 22
	menu.font_menu = love.graphics.newFont("path-to-font.ttf, 26) --default is same as the font_desc but size is 16
end

If you want to change the icon font:

menu.icon = love.graphics.newImage("path-to-image.png")

And that's it! Hope you got it!