Page 1 of 1

How do you make buttons?

Posted: Wed Feb 22, 2012 2:56 pm
by ok3y11
I wanna make a game with the start button but how do you make a text button?

Re: How do you make buttons?

Posted: Wed Feb 22, 2012 2:58 pm
by tentus
I'd recommend using Quickie if you're new to Lua.

Re: How do you make buttons?

Posted: Wed Feb 22, 2012 3:16 pm
by ok3y11
still dont get it.

Re: How do you make buttons?

Posted: Wed Feb 22, 2012 3:32 pm
by tentus
What don't you get? The more specific you are the more we can help you.

Re: How do you make buttons?

Posted: Wed Feb 22, 2012 4:27 pm
by coffee
ok3y11 wrote:I wanna make a game with the start button but how do you make a text button?
There isn't no imbued UI objects in LOVE. So you will need use a library like Quickie as tentus suggested. However if you need simple things and you want to learn doing yourself stuff maybe you can make a very simple and basic library.
Steps to do it:
1 - Draw a rectangle or load a image to use as button.
2 - Get rectangle/image and text size and determine where to print text over the rectangle/image
3 - in love.update call a routine that detects if it happen a click when mouse is over button area. Call the wanted routine if clicked
4 - in love.draw call a routine that draws the button/text.

Basically it's that. If you search in forum more people asked how to do that like this thread viewtopic.php?f=4&t=3386

Re: How do you make buttons?

Posted: Wed Feb 22, 2012 6:16 pm
by TheP3

Code: Select all

function love.mousepressed(x, y, click)
      if click == "l"(l as in left click) then
            if x >= (x pos of the button img) and x <= (x pos + width of img) and y >= (y pos of the button img) and y <= (y pos + width of img) then
                 --function
            end
      end
end
That's about it!

Re: How do you make buttons?

Posted: Wed Feb 22, 2012 7:31 pm
by MarekkPie
Quickie:

Code: Select all

GUI = require "Quickie"

function love.update(dt)
    if GUI.Button("Start", 200, 200, 100, 50) then
        -- start game function
    end
end

function love.draw()
    GUI.core.draw()
end
That's it.