Buttons using love.mousepressed?

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
RBXcpmoderator12345
Citizen
Posts: 59
Joined: Sat Mar 07, 2015 11:53 pm

Buttons using love.mousepressed?

Post by RBXcpmoderator12345 »

If I use an if statement to check the x and y of the mouse, and if it was clicked, it will only run if the mouse was on that certain position.
How would I make it so that when a sprite's area is clicked, it would run a block of code?
Um.. this is what I mean...

Code: Select all

function love.mousepressed(x, y, button)
if x == xcoord and y == ycoord and button == "l" then -- xcoord and ycoord are the coordinates of the button, but it would only trigger on that ---exact position
--code
end
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Buttons using love.mousepressed?

Post by Robin »

Suppose the width and height are stored in the variables button_width and button_height respectively, you'd use:

Code: Select all

function love.mousepressed(x, y, button)
if x >= xcoord and y >= ycoord and x <= xcoord + button_width and y <= ycoord + button_height and button == "l" then
--code
end
Help us help you: attach a .love.
RBXcpmoderator12345
Citizen
Posts: 59
Joined: Sat Mar 07, 2015 11:53 pm

Re: Buttons using love.mousepressed?

Post by RBXcpmoderator12345 »

Ok, attaching a .love
https://www.mediafire.com/?2gcjliirjw8evzd

and btw i tried making the default program to open love files windows explorer because i wanted to see the files without changing it to a zip, so i did that, and now i cant open .loves without dragging them to love.exe.... and i can't set love.exe to the default program to open .love files...
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Buttons using love.mousepressed?

Post by Robin »

That code is a mess. What is your question? I don't see any code for buttons.
Help us help you: attach a .love.
RBXcpmoderator12345
Citizen
Posts: 59
Joined: Sat Mar 07, 2015 11:53 pm

Re: Buttons using love.mousepressed?

Post by RBXcpmoderator12345 »

nevermind, i didn't realize i added it yet (the button code)
Post Reply

Who is online

Users browsing this forum: Bing [Bot], sawby and 1 guest