Skip to content

Commit

Permalink
Add timer scene
Browse files Browse the repository at this point in the history
WIP #144
  • Loading branch information
DannyDarwiche committed Aug 20, 2021
1 parent de9d993 commit 37f4937
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Scenes/LevelTimer.tscn
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 19 additions & 0 deletions Scripts/LevelTimer.gd
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 37f4937

Please sign in to comment.