Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

making a menu in love2d [closed]

Tags:

menu

love2d

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.

like image 925
cj1098 Avatar asked Jan 19 '26 23:01

cj1098


1 Answers

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.

like image 173
Darkwater Avatar answered Jan 22 '26 20:01

Darkwater



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!