0 votes

Hi All.

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

in Engine by (468 points)

2 Answers

+4 votes
Best answer

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()
by (12,290 points)
selected by

Thanks. And yes. it's all in the syntax...

0 votes

Check the docs to see how tweens work: https://docs.godotengine.org/en/stable/classes/class_tween.html

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()
by (28,744 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.