Determine clicks per second on a sprite

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By freaki2010

Hello Godot community,
i want to determine as exactly as possible the clicks per second on a sprite to calculate the points per second. If the user has not clicked for about 3 seconds the points should fall to the standard value. I’ve been looking for a possibility for half a day, but unfortunately I can’t find it.

I thank you for any help!

:bust_in_silhouette: Reply From: Sween123

You can use “Button”.
So the scene for this sprite is like:
my_sprite(Node2D)
–Button(Button)
–Graphic(Sprite)
For the Button, turn on the property “flat” so the graphic of a button won’s be displayed, yet able to detect mouse clicks.
Attach as script to the Node2D, and then connect the signal pressed() from Button to it.
Then you can just add variables to save all the informations of time or clickings. For example:

var timer = 0
var value = 0
function _on_Button_pressed():
  value += 1
function _process(delta):
  timer += delta
  #if timer >= 3: value = 0
  #or you can use this for gradually falling of the value: if timer >= 0.5 and value > 0: value -= 1    timer = 0

If you want the base value not to be zero (A standart value), just use another variable and replace the zeros with it.