I'm trying to create a game menu but am having trouble with making the surface of a image clickable.
What is expected to happen:
Mouse clicks on image, function runs.
What is happening:
Mouse clicks anywhere, and function does not run but returns error.
Code: Select all
Error: main.lua:23: attempt to index local menubuttonimg' (a boolean value)
Source Code:
Code: Select all
-- Call Backs --
function love.load()
x = 500
y = 400
menuscreenimg = love.graphics.newImage("placeholdermenu.png")
menubuttonimg = love.graphics.newImage("menubutton.png")
--testimg = love.graphics.newImage("logomario.png")
--love.graphics.setNewFont(12)
--love.graphics.setColor(0,0,0)
--love.graphics.setBackgroundColor(255,255,255)
-- testing for image collision
end
-- End of Call Backs --
-- Window Resolution --
success = love.window.setMode(1280, 720)
love.window.setTitle("Beta")
-- Mouse input for Menu Selection
function love.mousepressed(mx, my, button, menubuttonimg)
if button == 1
and mx >= x and mx < x + menubuttonimg:getWidth()
and my >= y and my < y + menubuttonimg:getHeight()
then print("IT WORKED!")
end
end
-- Menu Screen --
function love.draw()
love.graphics.draw(menuscreenimg) --1280, 720)
love.graphics.print("BETA",600, 300)
love.graphics.draw(menubuttonimg, 500, 400)
love.graphics.print("Start!", 600, 425)
end
-- For finding mouse position --
--[[
function love.draw()
mousey = love.mouse.getY()
mousex = love.mouse.getX()
love.graphics.print(mousex, mousey, 100, 100)
end
]]