Creating a menu in love2d

I am currently working with the love2D engine, and I am wondering how to create a simple user menu. Perhaps just with a few options, such as: Play, options, about, exit.

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

+3
source share
3 answers

To create a basic menu system, this is what you could do:

  • Create a table with button labels, callbacks, and possibly some other data.
  • In love.drawscroll through this table and draw buttons
  • In love.update(also possible in .draw if you want), check that the mouse is running over the button
  • If the mouse runs over the button and presses the button, call the button callback

, . , , , :

function pointInRectangle(pointx, pointy, rectx, recty, rectwidth, rectheight)
    return pointx > rectx and pointy > recty and pointx < rectx + rectwidth and pointy < recty + rectheight
end

, :

  • love.load pressed = false
  • love.mousereleased pressed = true
  • love.draw, end, pressed = false

, true, , .

+2
+1

I made a menu system for löve2d a while ago. Feel free to use it and know that you can and should change the draw function in accordance with your game schedule.

0
source

All Articles