From 1f8458687895876a663c025461cd23687e005320 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 3 Oct 2023 02:33:09 +0200 Subject: [PATCH] Make `Colored` not randomize hue on _ready --- color/Colored.gd | 11 ++++++----- converters/converter.gd | 6 ++++++ converters/gold_to_gem/gold_converter.tscn | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/color/Colored.gd b/color/Colored.gd index 02accbe..8fc24c7 100644 --- a/color/Colored.gd +++ b/color/Colored.gd @@ -3,7 +3,9 @@ class_name Colored @export var shader: Shader -@onready var hue: float: +@onready var parent: Sprite2D = get_parent() + +var hue: float: get: return hue set(value): @@ -11,13 +13,12 @@ class_name Colored if parent.material: parent.material.set_shader_parameter("hue", value) -@onready var parent: Sprite2D = get_parent() - func _ready(): var material = ShaderMaterial.new() - hue = Randomizer.rng.randf() material.shader = shader parent.material = material - + +func randomize_hue(): + hue = Randomizer.rng.randf() diff --git a/converters/converter.gd b/converters/converter.gd index 18ac54a..b7a14f2 100644 --- a/converters/converter.gd +++ b/converters/converter.gd @@ -57,3 +57,9 @@ func _on_input_event(_viewport: Node, event: InputEvent, _shape_idx: int): if is_pending_deletion: if event is InputEventMouseButton or event is InputEventScreenTouch: queue_free() + + +func _on_gold_converter_spawner_spawned(what: RigidBody2D): + # Randomize gem colors. + var colored: Colored = what.get_node("CollisionShape2D/Sprite/Colored") + colored.randomize_hue() diff --git a/converters/gold_to_gem/gold_converter.tscn b/converters/gold_to_gem/gold_converter.tscn index 95f195e..6d321f6 100644 --- a/converters/gold_to_gem/gold_converter.tscn +++ b/converters/gold_to_gem/gold_converter.tscn @@ -153,4 +153,5 @@ stream = ExtResource("11_lofho") [connection signal="input_event" from="." to="." method="_on_input_event"] [connection signal="collected" from="Collector" to="." method="_on_collector_collected" flags=18] [connection signal="goal" from="Collector" to="." method="_on_collector_goal" flags=18] +[connection signal="spawned" from="Spawner" to="." method="_on_gold_converter_spawner_spawned"] [connection signal="timeout" from="ConversionTimer" to="." method="_on_timer_timeout" flags=18]