Re: Help with GUI
Posted: Sun Feb 21, 2021 2:03 am
Edit: whoops, didn't read page 2, seems like you've got this working, I'm gonna leave here in case someone else wants it:
I might be understanding this wrong, but if you're asking how to make UI in general, this is the way to go
UI is a tricky thing to do, but pretty fun once you understand what to do:
For more complicated buttons, like onces that you can type in, you can make and use a "button.active" variable
I might be understanding this wrong, but if you're asking how to make UI in general, this is the way to go
UI is a tricky thing to do, but pretty fun once you understand what to do:
Code: Select all
function love.load()
-- So on here, let's setup some variables!
button = {}
button.position = {}
button.size = {}
button.hover = false
button.position.x = 50
button.position.y = 100
button.size.x = 200
button.size.y = 50
end
function love.draw()
-- Over here, We'll draw the button:
-- If button.hover == true then (change the color slightly) end
love.graphics.rectangle("fill", button.position.x, button.position.y, button.size.x, button.size.y)
end
function love.mousepressed(x, y)
-- Here we can check if the player pressed a button, and it's simple:
if ((x >= button.position.x) and (x <= button.position.x + button.size.x) and
(y >= button.position.y) and (y <= button.position.y + button.size.y)) then
-- The button has been pressed!
end
end
function love.mousemoved(x, y)
-- If the mouse is hovering over the button, it should light up to indicate it:
if ((x >= button.position.x) and (x <= button.position.x + button.size.x) and
(y >= button.position.y) and (y <= button.position.y + button.size.y)) then
-- The button is being hovered!
end
end