Advertisement
lil_sue

Time_display

May 14th, 2025
1,160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 1.40 KB | Gaming | 0 0
  1. extends RichTextLabel
  2.  
  3. # Time Variables
  4. var S: int = 0
  5. var M: int = 0
  6. var H: int = 0
  7.  
  8. @onready var secondhand: Timer = $"../../third_person/Time_display/secondhand"
  9. @onready var hide_timer: Timer = $"../../third_person/Time_display/hide_timer"
  10.  
  11.  
  12. func _ready() -> void:
  13.     # Ensure timers are connected
  14.     if not secondhand.timeout.is_connected(_on_secondhand_timeout):
  15.         secondhand.timeout.connect(_on_secondhand_timeout)
  16.  
  17.     hide_timer.wait_time = 5.0  # Fade out after 5 seconds
  18.     hide_timer.timeout.connect(_on_hide_timer_timeout)
  19.  
  20.     modulate.a = 0.0  # Start completely invisible
  21.     secondhand.start()  # Start the timer
  22.  
  23. func _on_secondhand_timeout() -> void:
  24.     S += 1
  25.     if S >= 60:
  26.         S = 0
  27.         M += 1
  28.     if M >= 60:
  29.         M = 0
  30.         H += 1
  31.     if H >= 24:
  32.         H = 0  # Reset at midnight
  33.  
  34.     set_text("%02d:%02d:%02d" % [H, M, S])
  35.  
  36.     # Debugging to verify correct updates
  37.     print("Time Updated:", "%02d:%02d:%02d" % [H, M, S])
  38.  
  39. func _input(event: InputEvent) -> void:
  40.     if event is InputEventKey and event.pressed:
  41.         if event.keycode in [KEY_7, KEY_8, KEY_9, KEY_0]:
  42.             fade_in_text()
  43.  
  44. func fade_in_text() -> void:
  45.     var tween = create_tween()
  46.     tween.tween_property(self, "modulate:a", 1.0, 1.0)  # Fade in over 1 second
  47.     hide_timer.start()  # Start countdown to fade out
  48.  
  49. func _on_hide_timer_timeout() -> void:
  50.     var tween = create_tween()
  51.     tween.tween_property(self, "modulate:a", 0.0, 1.5)  # Fade out smoothly
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement