warning_sign.gd 692 B

123456789101112131415161718192021222324252627282930313233343536
  1. extends LabelWithFont
  2. class_name WarningSign
  3. var n
  4. var DURATION = 3
  5. const V_OFFSET = 40
  6. func _init(_text, duration):
  7. font_path = "res://fonts/Now FL/Now-SemiBold.otf"
  8. font_size = 30
  9. modulate = Color8(255,0,255)
  10. text = _text
  11. DURATION = duration
  12. func _ready():
  13. var timer = Timer.new()
  14. timer.wait_time = DURATION
  15. timer.connect("timeout",self,'on_timeout')
  16. add_child(timer)
  17. timer.start()
  18. n = Node2D.new()
  19. n.z_index = 6
  20. n.z_as_relative = false
  21. get_parent().add_child(n)
  22. get_parent().remove_child(self)
  23. n.add_child(self)
  24. rect_position = Vector2(get_viewport().size.x/2.0 - rect_size.x/2.0, V_OFFSET)
  25. func on_timeout():
  26. self_destruct()
  27. func self_destruct():
  28. n.queue_free()