I'm doing a start menu for my game in Love2d. I need buttons for my "start game" and "quit game", of course. I know how to use text for buttons, but I do not know how to use actual pictures. I'm basing myself on this tutorial.
Help, please?
I'm doing a start menu for my game in Love2d. I need buttons for my "start game" and "quit game", of course. I know how to use text for buttons, but I do not know how to use actual pictures. I'm basing myself on this tutorial.
Help, please?
You are going to want to load your menu images into a love.load()
function and draw it in a love.draw()
function .
For instance, I make a file called menu.lua where I keep all my relevant menu data. menu.lua starts with menu = {}
which will create a new table called menu
. Then, in menu.lua:
function menu.load()
menu.start.img = love.graphics.newImage("start.jpg") -- load start.jpg
menu.exit.img = love.graphics.newImage("exit.jpg") -- load exit.jpg
end
function menu.draw()
love.graphics.draw(menu.start.img,x,y) -- draw start.jpg at (x,y)
love.graphics.draw(menu.exit.img,x,y) -- draw exit.jpg at (x,y)
end
After that, you call menu.load()
and menu.draw()
in your main.lua file.
That's how you load an image into a table and draw it.
The LOVE wiki can help you with these sort of questions.
First, use img = love.graphics.newImage('filename_here.png')
to load an image into the variable img
. Then, use love.graphics.draw(img, 50, 50)
to draw that image at coordinates 50, 50. Make sure you only load the image once though. If you