Question about tween method

Godot Version

4.2

Hi,
I’m very new to programming :slight_smile:
I was playing with tween, since it is pretty cool way to make some animation.

Question 1 :

In the Godot Documentation, they create a new variable to create a new tween with the object method ‘‘create_tween()’’

Why do I need to create a variable, can’t I just write :

self.create_tween().tween_property(self, “position”, Vector2(500, 100), 1)

Instead of:

var tween = create_tween()
tween.tween_property(self, “position”, Vector2(600, 600), 5)

Question 2 :

I understand the difference between _ready() and _process()

If I create a tween in the _process() fonction, this code is working :

tween.tween_property(self, “position”, Vector2(500, 100), 1)

But this code is not, it only work in the _ready() fonction (with the .from method) :

tween.tween_property(self, “position”, Vector2(500, 100), 1).from(Vector2(100, 100))

Why the first line of code is working in _process, but not the second line of code ?

Thx a lot !

You can just do that. You don’t need the self though. Just
create_tween().tween_property(self, “position”, Vector2(500, 100), 1)
should work fine.

Calling it from _ready should work. Calling it from _process isn’t good, because it will start a new tween every frame. Maybe some of your other code is interfering? Try attaching just this script to a Sprite2D:

extends Sprite2D

func _ready():
	create_tween().tween_property(self, "position", Vector2(500.,100.), 1.)
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.