Skip to reading
GDScript Programming & Godot

41. Tweens and temporary visual changes

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
Code example
func run() -> bool:
    var label := Label.new()
    label.text = "Fading notice"
    add_child(label)
    var animation: Tween = create_tween()
    animation.tween_property(label, "modulate:a", 0.0, 0.02)
    await animation.finished
    var finished: bool = is_zero_approx(label.modulate.a)
    label.queue_free()
    return finished

create_tween binds the Tween to this node’s lifetime. tween_property animates a property. By default successive steps run in sequence; set_parallel or parallel changes grouping. await finished lets the caller wait for the complete sequence.

Only tween properties the target actually has. A Label has modulate; a plain Node does not. A PCA record proxy is not automatically a Tween target for a rendered mesh. Get the native node deliberately or use the appropriate PCA action.

Avoid two systems writing the same property each frame. A Tween cannot reliably win a tug of war with PCA’s active camera controller, animation system or GUI state updater. Restore temporary presentation from saved game state when needed.

Page 50 of 378Permalink
Go to page