Skip to content

Commit 37f4937

Browse files
committed
Add timer scene
WIP #144
1 parent de9d993 commit 37f4937

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

Scenes/LevelTimer.tscn

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[gd_scene load_steps=4 format=2]
2+
3+
[ext_resource path="res://Scripts/LevelTimer.gd" type="Script" id=1]
4+
[ext_resource path="res://addons/gut/fonts/AnonymousPro-Regular.ttf" type="DynamicFontData" id=2]
5+
6+
[sub_resource type="DynamicFont" id=1]
7+
size = 100
8+
use_filter = true
9+
font_data = ExtResource( 2 )
10+
11+
[node name="Control" type="Control"]
12+
anchor_right = 1.0
13+
anchor_bottom = 1.0
14+
script = ExtResource( 1 )
15+
__meta__ = {
16+
"_edit_use_anchors_": false
17+
}
18+
19+
[node name="Label" type="Label" parent="."]
20+
anchor_left = 0.5
21+
anchor_top = 0.5
22+
anchor_right = 0.5
23+
anchor_bottom = 0.5
24+
margin_left = -441.5
25+
margin_top = -120.0
26+
margin_right = 441.5
27+
margin_bottom = 120.0
28+
grow_vertical = 2
29+
rect_clip_content = true
30+
size_flags_horizontal = 3
31+
size_flags_vertical = 1
32+
custom_fonts/font = SubResource( 1 )
33+
text = "Timer"
34+
align = 1
35+
valign = 1
36+
__meta__ = {
37+
"_edit_use_anchors_": false
38+
}

Scripts/LevelTimer.gd

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
extends Control
2+
3+
var time : float = 0.0
4+
var runTimer : bool = false
5+
6+
onready var label = get_node("Label")
7+
8+
func _process(delta):
9+
if runTimer:
10+
time += delta
11+
12+
var mils = fmod(time, 1) * 1000
13+
var secs = fmod(time, 60)
14+
var mins = floor(time / 60)
15+
16+
label.text = "%02d:%02d:%03d" % [mins, secs, mils]
17+
18+
func _ready():
19+
runTimer = true

0 commit comments

Comments
 (0)