How do you make buttons?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
ok3y11
Prole
Posts: 2
Joined: Wed Feb 22, 2012 2:52 pm

How do you make buttons?

Post by ok3y11 »

I wanna make a game with the start button but how do you make a text button?
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: How do you make buttons?

Post by tentus »

I'd recommend using Quickie if you're new to Lua.
Kurosuke needs beta testers
ok3y11
Prole
Posts: 2
Joined: Wed Feb 22, 2012 2:52 pm

Re: How do you make buttons?

Post by ok3y11 »

still dont get it.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: How do you make buttons?

Post by tentus »

What don't you get? The more specific you are the more we can help you.
Kurosuke needs beta testers
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: How do you make buttons?

Post 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
User avatar
TheP3
Citizen
Posts: 62
Joined: Tue Dec 20, 2011 9:20 pm

Re: How do you make buttons?

Post 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!
I write rules for my computer... I'm not the ruler of the world(yet)... Also, I livestream stuff http://NateAGeek.com/Live
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: How do you make buttons?

Post 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.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot], Google [Bot] and 7 guests