Struct Tween
Smoothly animates a node's properties over time.
struct Tween
;
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. Here is a brief usage example that causes a 2D node to 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"
(eg. 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 transitiontype
constant, and refers to the way the timing of the animation is handled (see http://easings.net/
for some examples). The second accepts an easetype
constant, and controls the where 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 transitiontype
constants with constant EASE_IN_OUT
, and use the one that looks best.
Properties
Name | Type | Description |
---|---|---|
playbackProcessMode [get, set]
|
Tween | The tween's animation process thread. See tweenprocessmode .
|
playbackSpeed [get, set]
|
double | 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 setActive or stopAll for this.
|
repeat [get, set]
|
bool | If true , the tween loops.
|
Methods
Name | Description |
---|---|
_removeByUid
|
|
followMethod
|
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 transitiontype for trans_type and easetype for ease_type parameters. These values control the timing and direction of the interpolation. See the class description for more information.
|
followProperty
|
Follows property of object and applies it on target_property of target , beginning from initial_val for duration seconds, delay seconds later.
Use transitiontype for trans_type and easetype for ease_type parameters. These values control the timing and direction of the interpolation. See the class description for more information.
|
getRuntime
|
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. |
getSpeedScale
|
|
getTweenProcessMode
|
|
interpolateCallback
|
Calls callback of object after duration . arg1 -arg5 are arguments to be passed to the callback.
|
interpolateDeferredCallback
|
Calls callback of object after duration on the main thread (similar to GodotObject ). arg1 -arg5 are arguments to be passed to the callback.
|
interpolateMethod
|
Animates method of object from initial_val to final_val for duration seconds, delay seconds later. Methods are called with consecutive values.
Use transitiontype for trans_type and easetype for ease_type parameters. These values control the timing and direction of the interpolation. See the class description for more information.
|
interpolateProperty
|
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 transitiontype for trans_type and easetype for ease_type parameters. These values control the timing and direction of the interpolation. See the class description for more information.
|
isActive
|
Returns true if any tweens are currently running.
Note: This method doesn't consider tweens that have ended.
|
isRepeat
|
|
remove
|
Stops animation and removes a tween, given its object and property/method pair. By default, all tweens are removed, unless key is specified.
|
removeAll
|
Stops animation and removes all tweens. |
reset
|
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
|
Resets all tweens to their initial values (the ones given, not those before the tween). |
resume
|
Continues animating a stopped tween, given its object and property/method pair. By default, all tweens are resumed, unless key is specified.
|
resumeAll
|
Continues animating all stopped tweens. |
seek
|
Sets the interpolation to the given time in seconds.
|
setActive
|
Activates/deactivates the tween. See also stopAll and resumeAll .
|
setRepeat
|
|
setSpeedScale
|
|
setTweenProcessMode
|
|
start
|
Starts the tween. You can define animations both before and after this. |
stop
|
Stops a tween, given its object and property/method pair. By default, all tweens are stopped, unless key is specified.
|
stopAll
|
Stops animating all tweens. |
targetingMethod
|
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 transitiontype for trans_type and easetype for ease_type parameters. These values control the timing and direction of the interpolation. See the class description for more information.
|
targetingProperty
|
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 transitiontype for trans_type and easetype for ease_type parameters. These values control the timing and direction of the interpolation. See the class description for more information.
|
tell
|
Returns the current time of the tween. |
Enums
Name | Description |
---|---|
Constants
|
|
EaseType
|
|
TransitionType
|
|
TweenProcessMode
|