From 37f4937bed183206b9735b038645fb4922f7158b Mon Sep 17 00:00:00 2001 From: DannyDarwiche Date: Thu, 19 Aug 2021 18:07:32 +0200 Subject: [PATCH] Add timer scene WIP #144 --- Scenes/LevelTimer.tscn | 38 ++++++++++++++++++++++++++++++++++++++ Scripts/LevelTimer.gd | 19 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 Scenes/LevelTimer.tscn create mode 100644 Scripts/LevelTimer.gd diff --git a/Scenes/LevelTimer.tscn b/Scenes/LevelTimer.tscn new file mode 100644 index 0000000..e40dee3 --- /dev/null +++ b/Scenes/LevelTimer.tscn @@ -0,0 +1,38 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://Scripts/LevelTimer.gd" type="Script" id=1] +[ext_resource path="res://addons/gut/fonts/AnonymousPro-Regular.ttf" type="DynamicFontData" id=2] + +[sub_resource type="DynamicFont" id=1] +size = 100 +use_filter = true +font_data = ExtResource( 2 ) + +[node name="Control" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Label" type="Label" parent="."] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -441.5 +margin_top = -120.0 +margin_right = 441.5 +margin_bottom = 120.0 +grow_vertical = 2 +rect_clip_content = true +size_flags_horizontal = 3 +size_flags_vertical = 1 +custom_fonts/font = SubResource( 1 ) +text = "Timer" +align = 1 +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} diff --git a/Scripts/LevelTimer.gd b/Scripts/LevelTimer.gd new file mode 100644 index 0000000..9ac8da9 --- /dev/null +++ b/Scripts/LevelTimer.gd @@ -0,0 +1,19 @@ +extends Control + +var time : float = 0.0 +var runTimer : bool = false + +onready var label = get_node("Label") + +func _process(delta): + if runTimer: + time += delta + + var mils = fmod(time, 1) * 1000 + var secs = fmod(time, 60) + var mins = floor(time / 60) + + label.text = "%02d:%02d:%03d" % [mins, secs, mils] + +func _ready(): + runTimer = true