Tweens are useful for animations requiring a numerical property to be interpolated over a range of values. The name tween comes from in-betweening, an animation technique where you specify keyframes and the computer interpolates the frames that appear between them.
godot.Tween is more suited than godot.AnimationPlayer for animations where you don't know the final values in advance. For example, interpolating a dynamically-chosen camera zoom value is best done with a godot.Tween node; it would be difficult to do the same thing with an godot.AnimationPlayer node.
Here is a brief usage example that makes a 2D node move smoothly between two positions:
var tween = get_node("Tween")
tween.interpolate_property($Node2D, "position",
Vector2(0, 0), Vector2(100, 100), 1,
Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
tween.start()
Many methods require a property name, such as "position" above. You can find the correct property name by hovering over the property in the Inspector. You can also provide the components of a property directly by using "property:component" (e.g. position:x), where it would only apply to that particular component.
Many of the methods accept trans_type and ease_type. The first accepts an godot.Tween_TransitionType constant, and refers to the way the timing of the animation is handled (see [https://easings.net/](easings.net) for some examples). The second accepts an godot.Tween_EaseType constant, and controls where the trans_type is applied to the interpolation (in the beginning, the end, or both). If you don't know which transition and easing to pick, you can try different godot.Tween_TransitionType constants with godot.Tween_EaseType.inOut, and use the one that looks best.
[https://raw.githubusercontent.com/godotengine/godot-docs/master/img/tween_cheatsheet.png](Tween easing and transition types cheatsheet)
Note: Tween methods will return false if the requested operation cannot be completed.
Constructor
Variables
read onlyonTweenStep:Signal<(object:Object, key:NodePath, elapsed:Float, value:Object) ‑> Void>
tween_step signal.
playbackProcessMode:Tween_TweenProcessMode
The tween's animation process thread. See godot.Tween_TweenProcessMode.
playbackSpeed:Single
The tween's speed multiplier. For example, set it to 1.0 for normal speed, 2.0 for two times normal speed, or 0.5 for half of the normal speed. A value of 0 pauses the animation, but see also godot.Tween.setActive or godot.Tween.stopAll for this.
Methods
followMethod(object:Object, method:String, initialVal:Dynamic, target:Object, targetMethod:String, duration:Single, ?transType:Tween_TransitionType, ?easeType:Tween_EaseType, ?delay:Single):Bool
Follows method of object and applies the returned value on target_method of target, beginning from initial_val for duration seconds, delay later. Methods are called with consecutive values.
Use godot.Tween_TransitionType for trans_type and godot.Tween_EaseType for ease_type parameters. These values control the timing and direction of the interpolation. See the class description for more information.
followProperty(object:Object, property:NodePath, initialVal:Dynamic, target:Object, targetProperty:NodePath, duration:Single, ?transType:Tween_TransitionType, ?easeType:Tween_EaseType, ?delay:Single):Bool
Follows property of object and applies it on target_property of target, beginning from initial_val for duration seconds, delay seconds later.
Use godot.Tween_TransitionType for trans_type and godot.Tween_EaseType for ease_type parameters. These values control the timing and direction of the interpolation. See the class description for more information.
getRuntime():Single
Returns the total time needed for all tweens to end. If you have two tweens, one lasting 10 seconds and the other 20 seconds, it would return 20 seconds, as by that time all tweens would have finished.
interpolateCallback(object:Object, duration:Single, callback:String, ?arg1:Dynamic, ?arg2:Dynamic, ?arg3:Dynamic, ?arg4:Dynamic, ?arg5:Dynamic):Bool
Calls callback of object after duration. arg1-arg5 are arguments to be passed to the callback.
interpolateDeferredCallback(object:Object, duration:Single, callback:String, ?arg1:Dynamic, ?arg2:Dynamic, ?arg3:Dynamic, ?arg4:Dynamic, ?arg5:Dynamic):Bool
Calls callback of object after duration on the main thread (similar to godot.Object.callDeferred). arg1-arg5 are arguments to be passed to the callback.
interpolateMethod(object:Object, method:String, initialVal:Dynamic, finalVal:Dynamic, duration:Single, ?transType:Tween_TransitionType, ?easeType:Tween_EaseType, ?delay:Single):Bool
Animates method of object from initial_val to final_val for duration seconds, delay seconds later. Methods are called with consecutive values.
Use godot.Tween_TransitionType for trans_type and godot.Tween_EaseType for ease_type parameters. These values control the timing and direction of the interpolation. See the class description for more information.
interpolateProperty(object:Object, property:NodePath, initialVal:Dynamic, finalVal:Dynamic, duration:Single, ?transType:Tween_TransitionType, ?easeType:Tween_EaseType, ?delay:Single):Bool
Animates property of object from initial_val to final_val for duration seconds, delay seconds later. Setting the initial value to null uses the current value of the property.
Use godot.Tween_TransitionType for trans_type and godot.Tween_EaseType for ease_type parameters. These values control the timing and direction of the interpolation. See the class description for more information.
isActive():Bool
Returns true if any tweens are currently running.
Note: This method doesn't consider tweens that have ended.
remove(object:Object, ?key:String):Bool
Stops animation and removes a tween, given its object and property/method pair. By default, all tweens are removed, unless key is specified.
reset(object:Object, ?key:String):Bool
Resets a tween to its initial value (the one given, not the one before the tween), given its object and property/method pair. By default, all tweens are removed, unless key is specified.
resetAll():Bool
Resets all tweens to their initial values (the ones given, not those before the tween).
resume(object:Object, ?key:String):Bool
Continues animating a stopped tween, given its object and property/method pair. By default, all tweens are resumed, unless key is specified.
setActive(active:Bool):Void
Activates/deactivates the tween. See also godot.Tween.stopAll and godot.Tween.resumeAll.
stop(object:Object, ?key:String):Bool
Stops a tween, given its object and property/method pair. By default, all tweens are stopped, unless key is specified.
targetingMethod(object:Object, method:String, initial:Object, initialMethod:String, finalVal:Dynamic, duration:Single, ?transType:Tween_TransitionType, ?easeType:Tween_EaseType, ?delay:Single):Bool
Animates method of object from the value returned by initial_method to final_val for duration seconds, delay seconds later. Methods are animated by calling them with consecutive values.
Use godot.Tween_TransitionType for trans_type and godot.Tween_EaseType for ease_type parameters. These values control the timing and direction of the interpolation. See the class description for more information.
targetingProperty(object:Object, property:NodePath, initial:Object, initialVal:NodePath, finalVal:Dynamic, duration:Single, ?transType:Tween_TransitionType, ?easeType:Tween_EaseType, ?delay:Single):Bool
Animates property of object from the current value of the initial_val property of initial to final_val for duration seconds, delay seconds later.
Use godot.Tween_TransitionType for trans_type and godot.Tween_EaseType for ease_type parameters. These values control the timing and direction of the interpolation. See the class description for more information.