Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends RichTextLabel
- # Time Variables
- var S: int = 0
- var M: int = 0
- var H: int = 0
- @onready var secondhand: Timer = $"../../third_person/Time_display/secondhand"
- @onready var hide_timer: Timer = $"../../third_person/Time_display/hide_timer"
- func _ready() -> void:
- # Ensure timers are connected
- if not secondhand.timeout.is_connected(_on_secondhand_timeout):
- secondhand.timeout.connect(_on_secondhand_timeout)
- hide_timer.wait_time = 5.0 # Fade out after 5 seconds
- hide_timer.timeout.connect(_on_hide_timer_timeout)
- modulate.a = 0.0 # Start completely invisible
- secondhand.start() # Start the timer
- func _on_secondhand_timeout() -> void:
- S += 1
- if S >= 60:
- S = 0
- M += 1
- if M >= 60:
- M = 0
- H += 1
- if H >= 24:
- H = 0 # Reset at midnight
- set_text("%02d:%02d:%02d" % [H, M, S])
- # Debugging to verify correct updates
- print("Time Updated:", "%02d:%02d:%02d" % [H, M, S])
- func _input(event: InputEvent) -> void:
- if event is InputEventKey and event.pressed:
- if event.keycode in [KEY_7, KEY_8, KEY_9, KEY_0]:
- fade_in_text()
- func fade_in_text() -> void:
- var tween = create_tween()
- tween.tween_property(self, "modulate:a", 1.0, 1.0) # Fade in over 1 second
- hide_timer.start() # Start countdown to fade out
- func _on_hide_timer_timeout() -> void:
- var tween = create_tween()
- tween.tween_property(self, "modulate:a", 0.0, 1.5) # Fade out smoothly
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement