Godot Version
4.7.1
Question
I was trying to get tween to work for scene transition effects. Previously I used animation player, but tween should work and is theoretically easier to set up (no new animation, new track, new node, new method, set keys for each property and time, etc..).
In the code below, SceneTransition is my CanvasLayer node with a full_rect ColorRect to cover the whole screen. I instance it in my main scene and call scene_transition.fade_out(), change scenes, and then scene_transition.fade_in().
However, it doesn’t work. Actually, it does work, but it fires off immediately without waiting. So my fade to black happens at the same time as my fade to clear. I even try to convince it to work with:
await tween.finished
That didn’t work, so I even tried a delay timer:
await get_tree().create_timer(duration).timeout
What am I missing? Again, the individual tweens work, but since they fire at the same time, they cancel each other out.
extends CanvasLayer
@onready var overlay = $ColorRect
func fade_out(duration = 0.5):
var tween = get_tree().create_tween()
tween.tween_property(overlay, "color", Color(0, 0, 0, 1), duration)
await tween.finished
wait(duration)
func fade_in(duration = 0.5):
var tween = get_tree().create_tween()
tween.tween_property(overlay, "color", Color(0, 0, 0, 0), duration)
await tween.finished
wait(duration)
func wait(duration):
await get_tree().create_timer(duration).timeout