Godot Version
v4.6.3.stable.steam [7d41c59c4]
Question
Hello, I’ve been trying to test out tweening on my own as a way to teach myself a little more about GDscript.
I wanted to see if I could use tweening to change a Sprite2D’s colors on a loop with the “modulate” property. At first I tried to write the code inside the _process() function and while it did modulate and loop the tweens it sent out a lot of errors so I decided to use the _ready() function instead and it worked fine there.
extends Sprite2D
@onready var sprite_2d: Sprite2D = $"."
var tween = create_tween()
func _ready() -> void:
tween.set_loops(0)
tween.tween_property(sprite_2d, "modulate", Color.RED, 0.5)
tween.tween_property(sprite_2d, "modulate", Color.BLUE, 0.5)
tween.tween_property(sprite_2d, "modulate", Color.GREEN, 0.5)
Though, I wanted to see if I could use the code outside of the _ready() function as I may need to do so in future scenarios. When I did do it even though there were no errors being sent in the debugger the tweening stopped working.
extends Sprite2D
@onready var sprite_2d: Sprite2D = $"."
var tween = create_tween()
func _ready() -> void:
pass
func tweening_colors() -> void:
tween.set_loops(0)
tween.tween_property(sprite_2d, "modulate", Color.RED, 0.5)
tween.tween_property(sprite_2d, "modulate", Color.BLUE, 0.5)
tween.tween_property(sprite_2d, "modulate", Color.GREEN, 0.5)
Is there a way I could rectify this? What am I missing?