small racing game im working on
Diffstat (limited to 'ui/timer.gd')
-rw-r--r--ui/timer.gd20
1 files changed, 20 insertions, 0 deletions
diff --git a/ui/timer.gd b/ui/timer.gd
new file mode 100644
index 0000000..e2508ed
--- /dev/null
+++ b/ui/timer.gd
@@ -0,0 +1,20 @@
+extends Label
+
+var elapsed_time: float = 0.0
+
+func _ready() -> void:
+ stop()
+
+func start() -> void:
+ set_process(true)
+
+func stop() -> void:
+ set_process(false)
+
+## format a number of seconds into m:s.ms
+func format(time: float) -> String:
+ return "%01d:%02d.%02d" % [time / 60, fmod(time, 60), fmod(time * 1000, 100)]
+
+func _process(delta: float) -> void:
+ elapsed_time += delta
+ text = format(elapsed_time) \ No newline at end of file