I've written a little Menu Engine and thought, it can be useful for others. So I share it here^^.
With this Menu Engine, it is possible to create a *dun dun duuun* Menu, that contains Entries which can be navigated & selected through Keyboard (WASD, Arrow-Keys, NumPad) and Mouse.
I've opened a github-Page for this (including a so-called API-Reference), which can be found here:
https://github.com/Astorek86/love2d-menuengine
Example Screenshot:
Sourcecode for this Example:
Code: Select all
local menuengine = require "menuengine"
local text = "Nothing was selected."
-- Mainmenu
local mainmenu
-- Start Game
local function start_game()
text = "Start Game was selected!"
end
-- Options
local function options()
text = "Options was selected!"
end
-- Quit Game
local function quit_game()
text = "Quit Game was selected!"
end
-- ----------
function love.load()
love.window.setMode(600,400)
love.graphics.setFont(love.graphics.newFont(20))
mainmenu = menuengine.new(200,100)
mainmenu:addEntry("Start Game", start_game)
mainmenu:addEntry("Options", options)
mainmenu:addSep()
mainmenu:addEntry("Quit Game", quit_game)
end
function love.update(dt)
mainmenu:update()
end
function love.draw()
love.graphics.clear()
love.graphics.print(text)
mainmenu:draw()
end
function love.keypressed(key, scancode, isrepeat)
menuengine.keypressed(scancode)
if scancode == "escape" then
love.event.quit()
end
end
function love.mousemoved(x, y, dx, dy, istouch)
menuengine.mousemoved(x, y)
end
- Supports different Colors:
- Different Fonts, Sizes...
- ...and Positions for every Entry
- It can handle with LÖVE's scaling-Options:
- It works with Sound-Objects: One for Moving through the Menu, one for Selecting an Entry. Every Entry can have it's own Sound-Object.
- You can hide and unhide Entries on-the-fly as you wish.
Alle Examples can be found in the menu-examples.zip.
Feel free to comment, and if you found bugs, please tell it .