I'm trying to make a menu screen. I seem to be doing something wrong in the mousepressed function since it isn't calling the function when the screen is clicked. Can anybody help me figure out why? I also have some code that makes the buttons red if you hold the mouse over them but I haven't finished it so don't mind it.
Thanks,
Code: Select all
function menu_load()
titlefont = love.graphics.newFont("Icons&Extras/Font/slkscr.ttf", 64)
buttonfont = love.graphics.newFont("Icons&Extras/Font/slkscr.ttf", 48)
menubuttons = {
startButton = {text = "Start", x = 200, y = 300, call = startgame},
exitButton = {text = "Exit", x = 200, y = 500, call = exitgame},
optionsButton = {text = "Options", x = 200, y = 400, call = openoptions}
}
end
function menu_draw()
love.graphics.setFont(titlefont)
love.graphics.printf("KNIGHTLY", 200, 100, 400, "center")
love.graphics.setFont(buttonfont)
for i, v in pairs(menubuttons) do
love.graphics.printf(v.text, v.x, v.y, 400, "center")
end
end
function menu_update(Somethinglikedt)
end
function menu_mousepressed(x, y, button)
for i, v in pairs(menubuttons) do
if x > v.x and x < v.x + 200 and y > v.y and y < v.y + 35 then
v.call()
end
end
end
function menu_mousemoved(x, y)
for i, v in pairs(menubuttons) do
if x > v.x and x < v.x + 400 and y > v.y and y < v.y + 35 then
buttonColour = love.graphics.setColor(255, 0, 0)
else
buttonColour = love.graphics.setColor(255, 255, 255)
end
end
end
function startgame()
print("startinggame")
end
function exitgame()
print("quiting")
end
function openoptions()
print("fetchingoptions")
end