3

I'm currently working with the love2D game engine and am curious how to create just a simple user menu. Maybe just with a few options such as: Play, options, about, exit.

Are there any good tutorials out there for creating a custom game menu? I just want to get started.

cj1098
  • 1,560
  • 6
  • 32
  • 60

3 Answers3

3

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.

Darkwater
  • 1,358
  • 2
  • 12
  • 25
1

I recommend using LoveFrames. It is great.

Josh Bothun
  • 1,324
  • 9
  • 9
0

I made a menu system for löve2d some time ago. Feel free to use it, and know that you can and should modify the draw function to suit your game's graphics.

nkorth
  • 1,684
  • 1
  • 12
  • 28