1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-25 09:04:19 +00:00

Make Colored not randomize hue on _ready

This commit is contained in:
Steffo 2023-10-03 02:33:09 +02:00
parent bf6b56eb75
commit 1f84586878
Signed by: steffo
GPG key ID: 2A24051445686895
3 changed files with 13 additions and 5 deletions

View file

@ -3,7 +3,9 @@ class_name Colored
@export var shader: Shader @export var shader: Shader
@onready var hue: float: @onready var parent: Sprite2D = get_parent()
var hue: float:
get: get:
return hue return hue
set(value): set(value):
@ -11,13 +13,12 @@ class_name Colored
if parent.material: if parent.material:
parent.material.set_shader_parameter("hue", value) parent.material.set_shader_parameter("hue", value)
@onready var parent: Sprite2D = get_parent()
func _ready(): func _ready():
var material = ShaderMaterial.new() var material = ShaderMaterial.new()
hue = Randomizer.rng.randf()
material.shader = shader material.shader = shader
parent.material = material parent.material = material
func randomize_hue():
hue = Randomizer.rng.randf()

View file

@ -57,3 +57,9 @@ func _on_input_event(_viewport: Node, event: InputEvent, _shape_idx: int):
if is_pending_deletion: if is_pending_deletion:
if event is InputEventMouseButton or event is InputEventScreenTouch: if event is InputEventMouseButton or event is InputEventScreenTouch:
queue_free() 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()

View file

@ -153,4 +153,5 @@ stream = ExtResource("11_lofho")
[connection signal="input_event" from="." to="." method="_on_input_event"] [connection signal="input_event" from="." to="." method="_on_input_event"]
[connection signal="collected" from="Collector" to="." method="_on_collector_collected" flags=18] [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="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] [connection signal="timeout" from="ConversionTimer" to="." method="_on_timer_timeout" flags=18]