TapTapTapTap/Main.gd

26 lines
466 B
GDScript3
Raw Normal View History

2021-10-27 22:01:28 +00:00
extends Control
var times = []
var i = 0
var bpm: float
onready var button = $Button
onready var DisplayBPM = $Label
func _ready():
button.connect("pressed", self, "_button_pressed")
func _button_pressed():
times.append(OS.get_ticks_usec())
if (i!=0):
var delta = times[i]-times[i-1]
print(delta)
if (i > 8 && delta > 240000000 / bpm):
i = 0
bpm = 0
else:
bpm = 60000000 / delta
i += 1
DisplayBPM.text = str(bpm) + "BPM"
else:
i += 1