online multiplayer chess game (note server currently down)
Diffstat (limited to 'ui/background/ColorfullBackground.gd')
-rw-r--r--ui/background/ColorfullBackground.gd29
1 files changed, 11 insertions, 18 deletions
diff --git a/ui/background/ColorfullBackground.gd b/ui/background/ColorfullBackground.gd
index de5ada5..18e4398 100644
--- a/ui/background/ColorfullBackground.gd
+++ b/ui/background/ColorfullBackground.gd
@@ -3,37 +3,30 @@ extends ColorRect
export(PoolColorArray) var colors
export(float) var length := 2.8
+var rainbow := true
onready var fallback_color = color
-var rainbow := true setget set_rainbow
-var tween := Tween.new()
-var timer := Timer.new()
-
static func rand(clr) -> float:
return clamp(clr + rand_range(0, .1) if randi() % 2 else clr - rand_range(0, .1), 0, 1)
-func set_rainbow(newrainbow):
- rainbow = newrainbow
- change_color()
-
-
func _ready() -> void:
randomize()
- add_child(tween)
- add_child(timer)
- timer.connect("timeout", self, "change_color")
color = colors[randi() % colors.size()]
change_color()
+func create_timer():
+ get_tree().create_timer(length).connect("timeout", self, "change_color")
+
+
func change_color() -> void:
- timer.start(length)
+ create_timer()
+ var tween = create_tween().set_trans(Tween.TRANS_ELASTIC)
if rainbow:
- var clr: Color = colors[randi() % colors.size()]
- clr = Color(rand(clr.r), rand(clr.g), rand(clr.b), 1)
- tween.interpolate_property(self, "color", color, clr, length, Tween.TRANS_ELASTIC)
+ var chosen: Color = colors[randi() % colors.size()]
+ var clr = Color(rand(chosen.r), rand(chosen.g), rand(chosen.b), 1)
+ tween.tween_property(self, "color", clr, length)
else:
- tween.interpolate_property(self, "color", color, fallback_color, length, Tween.TRANS_ELASTIC)
- tween.start()
+ tween.tween_property(self, "color", fallback_color, length)