classes/class_tween #304
Replies: 6 comments 5 replies
-
When tweening methods, unlike the "look_at()" method, that use callables that bind to the first argument. A workaround may be used: var following_node = self
var starting_position = following_node.global_position
var tween = create_tween()
tween.tween_method(func(i): following_node.global_position = starting_position.lerp(target_node.global_position, i), 0.0, 1.0, 5.0) # This function follows a target node for 5 seconds |
Beta Was this translation helpful? Give feedback.
-
I am trying to tween a ColorRect's alpha property using: tween.tween_property(fader, "color:a", 0.0, 1.0).from(1.0) I get an error, "Cannot call method 'from' on a null value." The full function is: func fade_in() -> void:
var tween = create_tween()
tween.tween_interval(0.1)
tween.tween_property(fader, "color:a", 0.0, 1.0).from(1.0) The fader is an onready node variable. This worked in 4.2.2 so I'm guessing something changed and "color:a" no longer works so it returns a null? |
Beta Was this translation helpful? Give feedback.
-
I'm finding that this construction: if tween:
tween.kill() # Abort the previous animation.
tween = create_tween() in the case that the tween exists, even if new and untasked, the tween won't animate (or not right away at least; I didn't have the patience to wait). Taking out the kill part and just creating a new tween for every new thing to do, seems to work always. |
Beta Was this translation helpful? Give feedback.
-
In the code snippet for var tween = create_tween()
tween.tween_method(look_at.bind(Vector3.UP), Vector3(-1, 0, -1), Vector3(1, 0, -1), 1)
# The look_at() method takes up vector as second argument. Shouldn't it be this? tween.tween_method(look_at.bind(null, Vector3.UP), Vector3(-1, 0, -1), Vector3(1, 0, -1), 1) Since otherwise we'd be binding |
Beta Was this translation helpful? Give feedback.
-
I pulled my hair out for hours trying to figure out how to use Tween tween = CreateTween();
tween.TweenProperty(this, "position", new Vector2(300, 0), 0.5); // Uses EASE_IN_OUT.
tween.SetEase(Tween.EaseType.In);
tween.TweenProperty(this, "rotation_degrees", 45.0, 0.5); // Uses EASE_IN. The Tween tween = CreateTween();
tween.TweenProperty(this, "position", new Vector2(300, 0), 0.5); // Uses EASE_IN_OUT.
tween.SetTrans(Tween.TransitionType.Sine);
tween.tween_property(self, "rotation_degrees", 45.0, 0.5); // Uses TRANS_SINE. |
Beta Was this translation helpful? Give feedback.
-
var tween: Tween
var id: int = 0
func _on_button_pressed() -> void:
if tween:
tween.kill()
print("start")
id += 1
tween = create_tween()
tween.tween_callback(func():
print("done"+str(id))
).set_delay(3)
await tween.finished
print("finished"+str(id)) Is it okay to have orphans in await if a button is pressed multiple times in 3 seconds? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
classes/class_tween
Inherits: RefCounted< Object Lightweight object used for general-purpose animation via script, using Tweener s. Description: Tweens are mostly useful for animations requiring a numerical property t...
https://docs.godotengine.org/en/stable/classes/class_tween.html
Beta Was this translation helpful? Give feedback.
All reactions