To make a basic menu system, this is what you could do:
- Create a table with the buttons' label, callback, and maybe some other data
- In
love.draw
, loop through that table and draw the buttons
- In
love.update
(also possible in .draw if you want), check if the mouse is hovering over the button
- If the mouse is hovering over the button and has pressed the button, call the button's callback
Now I can't give you all the code needed, because it depends on the rest of your code. However, I can give you a function to check if the mouse is hovering a button:
function pointInRectangle(pointx, pointy, rectx, recty, rectwidth, rectheight)
return pointx > rectx and pointy > recty and pointx < rectx + rectwidth and pointy < recty + rectheight
end
And the logic behind checking if the user has pressed the mouse:
- In
love.load
, add pressed = false
- In
love.mousereleased
, add pressed = true
- At the very end of
love.draw
, just before end
, add pressed = false
Now, if pressed equals true, you know that the user has just released the mouse button.