How to tween the position of a label node?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

Hi All.

What is the best way to tween a position (rect_position) of a label node on one axis?

:bust_in_silhouette: Reply From: jgodfrey

Here’s an example of tweening the position of a label on the X axis. The only trick is in knowing the syntax of accessing a single component of the rect_position object…

func _ready():
	var tween = Tween.new();
	tween.interpolate_property($Label, "rect_position:x", 100, 200, 3, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
	add_child(tween)
	tween.start()

Thanks. And yes. it’s all in the syntax…

Macryc | 2020-03-08 21:10

:bust_in_silhouette: Reply From: Zylann

Check the docs to see how tweens work: Tween — Godot Engine (stable) documentation in English

Then, by simple substitution, I guess it’s done this way:

var tween = get_node("Tween")
tween.interpolate_property($YourLabel, "rect_position",
        Vector2(0, 0), Vector2(0, 100), 1,
        Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
tween.start()