Lightweight object used for general-purpose animation via script, using [Tweener]s. [SceneTreeTween] is a tween managed by the scene tree. As opposed to [Tween], it does not require the instantiation of a node. [SceneTreeTween]s are more light-weight than [AnimationPlayer], so they are very much suited for simple animations or general tasks that don't require visual tweaking provided by the editor. They can be used in a fire-and-forget manner for some logic that normally would be done by code. You can e.g. make something shoot periodically by using a looped [CallbackTweener] with a delay. A [SceneTreeTween] can be created by using either [method SceneTree.create_tween] or [method Node.create_tween]. [SceneTreeTween]s created manually (i.e. by using [code]Tween.new()[/code]) are invalid. They can't be used for tweening values, but you can do manual interpolation with [method interpolate_value]. A [SceneTreeTween] animation is composed of a sequence of [Tweener]s, which by default are executed one after another. You can create a sequence by appending [Tweener]s to the [SceneTreeTween]. Animating something with a [Tweener] is called tweening. Example tweening sequence looks like this: [codeblock] var tween = get_tree().create_tween() tween.tween_property($Sprite, "modulate", Color.red, 1) tween.tween_property($Sprite, "scale", Vector2(), 1) tween.tween_callback($Sprite, "queue_free") [/codeblock] This sequence will make the [code]$Sprite[/code] node turn red, then shrink and finally the [method Node.queue_free] is called to remove the sprite. See methods [method tween_property], [method tween_interval], [method tween_callback] and [method tween_method] for more usage information. When a [Tweener] is created with one of the [code]tween_*[/code] methods, a chained method call can be used to tweak the properties of this [Tweener]. For example, if you want to set different transition type in the above example, you can do: [codeblock] var tween = get_tree().create_tween() tween.tween_property($Sprite, "modulate", Color.red, 1).set_trans(Tween.TRANS_SINE) tween.tween_property($Sprite, "scale", Vector2(), 1).set_trans(Tween.TRANS_BOUNCE) tween.tween_callback($Sprite, "queue_free") [/codeblock] Most of the [SceneTreeTween] methods can be chained this way too. In this example the [SceneTreeTween] is bound and have set a default transition: [codeblock] var tween = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_ELASTIC) tween.tween_property($Sprite, "modulate", Color.red, 1) tween.tween_property($Sprite, "scale", Vector2(), 1) tween.tween_callback($Sprite, "queue_free") [/codeblock] Another interesting use for [SceneTreeTween]s is animating arbitrary set of objects: [codeblock] var tween = create_tween() for sprite in get_children(): tween.tween_property(sprite, "position", Vector2(), 1) [/codeblock] In the example above, all children of a node are moved one after another to position (0, 0). Some [Tweener]s use transitions and eases. The first accepts an [enum Tween.TransitionType] constant, and refers to the way the timing of the animation is handled (see [url=https://easings.net/]easings.net[/url] for some examples). The second accepts an [enum Tween.EaseType] constant, and controls where the [code]trans_type[/code] 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 [enum Tween.TransitionType] constants with [constant Tween.EASE_IN_OUT], and use the one that looks best. [url=https://raw.githubusercontent.com/godotengine/godot-docs/master/img/tween_cheatsheet.png]Tween easing and transition types cheatsheet[/url] [b]Note:[/b] All [SceneTreeTween]s will automatically start by default. To prevent a [SceneTreeTween] from autostarting, you can call [method stop] immediately after it was created. Binds this [SceneTreeTween] with the given [code]node[/code]. [SceneTreeTween]s are processed directly by the [SceneTree], so they run independently of the animated nodes. When you bind a [Node] with the [SceneTreeTween], the [SceneTreeTween] will halt the animation when the object is not inside tree and the [SceneTreeTween] will be automatically killed when the bound object is freed. Also [constant TWEEN_PAUSE_BOUND] will make the pausing behavior dependent on the bound node. For a shorter way to create and bind a [SceneTreeTween], you can use [method Node.create_tween]. Used to chain two [Tweener]s after [method set_parallel] is called with [code]true[/code]. [codeblock] var tween = create_tween().set_parallel(true) tween.tween_property(...) tween.tween_property(...) # Will run parallelly with above. tween.chain().tween_property(...) # Will run after two above are finished. [/codeblock] Processes the [SceneTreeTween] by given [code]delta[/code] value, in seconds. Mostly useful when the [SceneTreeTween] is paused, for controlling it manually. Can also be used to end the [SceneTreeTween] animation immediately, by using [code]delta[/code] longer than the whole duration. Returns [code]true[/code] if the [SceneTreeTween] still has [Tweener]s that haven't finished. [b]Note:[/b] The [SceneTreeTween] will become invalid after finished, but you can call [method stop] after the step, to keep it and reset. Returns the total time in seconds the [SceneTreeTween] has been animating (i.e. time since it started, not counting pauses etc.). The time is affected by [method set_speed_scale] and [method stop] will reset it to [code]0[/code]. [b]Note:[/b] As it results from accumulating frame deltas, the time returned after the [SceneTreeTween] has finished animating will be slightly greater than the actual [SceneTreeTween] duration. This method can be used for manual interpolation of a value, when you don't want [SceneTreeTween] to do animating for you. It's similar to [method @GDScript.lerp], but with support for custom transition and easing. [code]initial_value[/code] is the starting value of the interpolation. [code]delta_value[/code] is the change of the value in the interpolation, i.e. it's equal to [code]final_value - initial_value[/code]. [code]elapsed_time[/code] is the time in seconds that passed after the interpolation started and it's used to control the position of the interpolation. E.g. when it's equal to half of the [code]duration[/code], the interpolated value will be halfway between initial and final values. This value can also be greater than [code]duration[/code] or lower than 0, which will extrapolate the value. [code]duration[/code] is the total time of the interpolation. [b]Note:[/b] If [code]duration[/code] is equal to [code]0[/code], the method will always return the final value, regardless of [code]elapsed_time[/code] provided. Returns whether the [SceneTreeTween] is currently running, i.e. it wasn't paused and it's not finished. Returns whether the [SceneTreeTween] is valid. A valid [SceneTreeTween] is a [SceneTreeTween] contained by the scene tree (i.e. the array from [method SceneTree.get_processed_tweens] will contain this [SceneTreeTween]). [SceneTreeTween] might become invalid when it has finished tweening or was killed, also when created with [code]Tween.new()[/code]. Invalid [SceneTreeTween] can't have [Tweener]s appended, because it can't animate them. You can however still use [method interpolate_value]. Aborts all tweening operations and invalidates the [SceneTreeTween]. Makes the next [Tweener] run parallelly to the previous one. Example: [codeblock] var tween = create_tween() tween.tween_property(...) tween.parallel().tween_property(...) tween.parallel().tween_property(...) [/codeblock] All [Tweener]s in the example will run at the same time. You can make the [SceneTreeTween] parallel by default by using [method set_parallel]. Pauses the tweening. The animation can be resumed by using [method play]. Resumes a paused or stopped [SceneTreeTween]. Sets the default ease type for [PropertyTweener]s and [MethodTweener]s animated by this [SceneTreeTween]. Sets the number of times the tweening sequence will be repeated, i.e. [code]set_loops(2)[/code] will run the animation twice. Calling this method without arguments will make the [SceneTreeTween] run infinitely, until it is either killed by [method kill] or by freeing bound node, or all the animated objects have been freed (which makes further animation impossible). [b]Warning:[/b] Make sure to always add some duration/delay when using infinite loops. 0-duration looped animations (e.g. single [CallbackTweener] with no delay or [PropertyTweener] with invalid node) are equivalent to infinite [code]while[/code] loops and will freeze your game. If a [SceneTreeTween]'s lifetime depends on some node, always use [method bind_node]. If [code]parallel[/code] is [code]true[/code], the [Tweener]s appended after this method will by default run simultaneously, as opposed to sequentially. Determines the behavior of the [SceneTreeTween] when the [SceneTree] is paused. Check [enum TweenPauseMode] for options. Default value is [constant TWEEN_PAUSE_BOUND]. Determines whether the [SceneTreeTween] should run during idle frame (see [method Node._process]) or physics frame (see [method Node._physics_process]. Default value is [constant Tween.TWEEN_PROCESS_IDLE]. Scales the speed of tweening. This affects all [Tweener]s and their delays. Sets the default transition type for [PropertyTweener]s and [MethodTweener]s animated by this [SceneTreeTween]. Stops the tweening and resets the [SceneTreeTween] to its initial state. This will not remove any appended [Tweener]s. Creates and appends a [CallbackTweener]. This method can be used to call an arbitrary method in any object. Use [code]binds[/code] to bind additional arguments for the call. Example: object that keeps shooting every 1 second. [codeblock] var tween = get_tree().create_tween().set_loops() tween.tween_callback(self, "shoot").set_delay(1) [/codeblock] Example: turning a sprite red and then blue, with 2 second delay. [codeblock] var tween = get_tree().create_tween() tween.tween_callback($Sprite, "set_modulate", [Color.red]).set_delay(2) tween.tween_callback($Sprite, "set_modulate", [Color.blue]).set_delay(2) [/codeblock] Creates and appends an [IntervalTweener]. This method can be used to create delays in the tween animation, as an alternative for using the delay in other [Tweener]s or when there's no animation (in which case the [SceneTreeTween] acts as a timer). [code]time[/code] is the length of the interval, in seconds. Example: creating an interval in code execution. [codeblock] # ... some code yield(create_tween().tween_interval(2), "finished") # ... more code [/codeblock] Example: creating an object that moves back and forth and jumps every few seconds. [codeblock] var tween = create_tween().set_loops() tween.tween_property($Sprite, "position:x", 200.0, 1).as_relative() tween.tween_callback(self, "jump") tween.tween_interval(2) tween.tween_property($Sprite, "position:x", -200.0, 1).as_relative() tween.tween_callback(self, "jump") tween.tween_interval(2) [/codeblock] Creates and appends a [MethodTweener]. This method is similar to a combination of [method tween_callback] and [method tween_property]. It calls a method over time with a tweened value provided as an argument. The value is tweened between [code]from[/code] and [code]to[/code] over the time specified by [code]duration[/code], in seconds. Use [code]binds[/code] to bind additional arguments for the call. You can use [method MethodTweener.set_ease] and [method MethodTweener.set_trans] to tweak the easing and transition of the value or [method MethodTweener.set_delay] to delay the tweening. Example: making a 3D object look from one point to another point. [codeblock] var tween = create_tween() tween.tween_method(self, "look_at", Vector3(-1, 0, -1), Vector3(1, 0, -1), 1, [Vector3.UP]) # The look_at() method takes up vector as second argument. [/codeblock] Example: setting a text of a [Label], using an intermediate method and after a delay. [codeblock] func _ready(): var tween = create_tween() tween.tween_method(self, "set_label_text", 0, 10, 1).set_delay(1) func set_label_text(value: int): $Label.text = "Counting " + str(value) [/codeblock] Creates and appends a [PropertyTweener]. This method tweens a [code]property[/code] of an [code]object[/code] between an initial value and [code]final_val[/code] in a span of time equal to [code]duration[/code], in seconds. The initial value by default is a value at the time the tweening of the [PropertyTweener] start. For example: [codeblock] var tween = create_tween() tween.tween_property($Sprite, "position", Vector2(100, 200), 1) tween.tween_property($Sprite, "position", Vector2(200, 300), 1) [/codeblock] will move the sprite to position (100, 200) and then to (200, 300). If you use [method PropertyTweener.from] or [method PropertyTweener.from_current], the starting position will be overwritten by the given value instead. See other methods in [PropertyTweener] to see how the tweening can be tweaked further. [b]Note:[/b] 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 [code]"property:component"[/code] (eg. [code]position:x[/code]), where it would only apply to that particular component. Example: moving object twice from the same position, with different transition types. [codeblock] var tween = create_tween() tween.tween_property($Sprite, "position", Vector2.RIGHT * 300, 1).as_relative().set_trans(Tween.TRANS_SINE) tween.tween_property($Sprite, "position", Vector2.RIGHT * 300, 1).as_relative().from_current().set_trans(Tween.TRANS_EXPO) [/codeblock] Emitted when the [SceneTreeTween] has finished all tweening. Never emitted when the [SceneTreeTween] is set to infinite looping (see [method set_loops]). [b]Note:[/b] The [SceneTreeTween] is removed (invalidated) after this signal is emitted, but it doesn't happen immediately, but on the next processing frame. Calling [method stop] inside the signal callback will preserve the [SceneTreeTween]. Emitted when a full loop is complete (see [method set_loops]), providing the loop index. This signal is not emitted after final loop, use [signal finished] instead for this case. Emitted when one step of the [SceneTreeTween] is complete, providing the step index. One step is either a single [Tweener] or a group of [Tweener]s running parallelly. If the [SceneTreeTween] has a bound node, it will process when that node can process (see [member Node.pause_mode]). Otherwise it's the same as [constant TWEEN_PAUSE_STOP]. If [SceneTree] is paused, the [SceneTreeTween] will also pause. The [SceneTreeTween] will process regardless of whether [SceneTree] is paused.