Page 1 of 1

How to make a single click button

Posted: Tue Apr 25, 2023 2:16 pm
by Dangerous beetle
I want to make a button just like the white circle-shaped button used in google doodle championship (not the joystick but the button), I want the button to be single click........by that I mean on clicking that button, a variable "buttonClicked" will go true and instantly go false so that holding the button won't lead to repeating action, one more example is like the "btnp()" function used in tic 80, the player needs to click the button again and again instead of holding the button to repeat the action.....I hope you guys understood what I meant, Please help as soon as possible :cry:

Re: How to make a single click button

Posted: Tue Apr 25, 2023 4:57 pm
by BrotSagtMist

Code: Select all

Clicks=0
function love.mousepressed(x,y,b)
 Press={x,y}
end
function button(x,y,r)
 love.graphics.circle("line",x,y,r)
 if Press then 
  if ((x-Press[1])^2+(y-Press[2])^2)<r^2 then
   Press=nil
   return true
  end
 end
end
function love.draw()
 love.graphics.print(Clicks)
 if button(160,160,60) then  Clicks=Clicks+1 end 
 if button(300,30,20) then love.event.quit() end
end

Re: How to make a single click button

Posted: Wed Apr 26, 2023 2:17 am
by Dangerous beetle
Thanks a lot it worked! :)