Debian Codegraph @

doc/classes/Tween.xml

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <class name="Tween" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3 <brief_description>
4 Lightweight object used for general-purpose animation via script, using [Tweener]s.
5 </brief_description>
6 <description>
7 Tweens are mostly useful for animations requiring a numerical property to be interpolated over a range of values. The name [i]tween[/i] comes from [i]in-betweening[/i], an animation technique where you specify [i]keyframes[/i] and the computer interpolates the frames that appear between them. Animating something with a [Tween] is called tweening.
8 [Tween] is more suited than [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 [Tween]; it would be difficult to do the same thing with an [AnimationPlayer] node. Tweens are also 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.
9 A [Tween] can be created by using either [method SceneTree.create_tween] or [method Node.create_tween]. [Tween]s created manually (i.e. by using [code]Tween.new()[/code]) are invalid and can't be used for tweening values.
10 A tween animation is created by adding [Tweener]s to the [Tween] object, using [method tween_property], [method tween_interval], [method tween_callback] or [method tween_method]:
11 [codeblocks]
12 [gdscript]
13 var tween = get_tree().create_tween()
14 tween.tween_property($Sprite, "modulate", Color.RED, 1.0)
15 tween.tween_property($Sprite, "scale", Vector2(), 1.0)
16 tween.tween_callback($Sprite.queue_free)
17 [/gdscript]
18 [csharp]
19 Tween tween = GetTree().CreateTween();
20 tween.TweenProperty(GetNode("Sprite"), "modulate", Colors.Red, 1.0f);
21 tween.TweenProperty(GetNode("Sprite"), "scale", Vector2.Zero, 1.0f);
22 tween.TweenCallback(Callable.From(GetNode("Sprite").QueueFree));
23 [/csharp]
24 [/codeblocks]
25 This sequence will make the [code]$Sprite[/code] node turn red, then shrink, before finally calling [method Node.queue_free] to free the sprite. [Tweener]s are executed one after another by default. This behavior can be changed using [method parallel] and [method set_parallel].
26 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 a different transition type in the above example, you can use [method set_trans]:
27 [codeblocks]
28 [gdscript]
29 var tween = get_tree().create_tween()
30 tween.tween_property($Sprite, "modulate", Color.RED, 1.0).set_trans(Tween.TRANS_SINE)
31 tween.tween_property($Sprite, "scale", Vector2(), 1.0).set_trans(Tween.TRANS_BOUNCE)
32 tween.tween_callback($Sprite.queue_free)
33 [/gdscript]
34 [csharp]
35 Tween tween = GetTree().CreateTween();
36 tween.TweenProperty(GetNode("Sprite"), "modulate", Colors.Red, 1.0f).SetTrans(Tween.TransitionType.Sine);
37 tween.TweenProperty(GetNode("Sprite"), "scale", Vector2.Zero, 1.0f).SetTrans(Tween.TransitionType.Bounce);
38 tween.TweenCallback(Callable.From(GetNode("Sprite").QueueFree));
39 [/csharp]
40 [/codeblocks]
41 Most of the [Tween] methods can be chained this way too. In the following example the [Tween] is bound to the running script's node and a default transition is set for its [Tweener]s:
42 [codeblocks]
43 [gdscript]
44 var tween = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_ELASTIC)
45 tween.tween_property($Sprite, "modulate", Color.RED, 1.0)
46 tween.tween_property($Sprite, "scale", Vector2(), 1.0)
47 tween.tween_callback($Sprite.queue_free)
48 [/gdscript]
49 [csharp]
50 var tween = GetTree().CreateTween().BindNode(this).SetTrans(Tween.TransitionType.Elastic);
51 tween.TweenProperty(GetNode("Sprite"), "modulate", Colors.Red, 1.0f);
52 tween.TweenProperty(GetNode("Sprite"), "scale", Vector2.Zero, 1.0f);
53 tween.TweenCallback(Callable.From(GetNode("Sprite").QueueFree));
54 [/csharp]
55 [/codeblocks]
56 Another interesting use for [Tween]s is animating arbitrary sets of objects:
57 [codeblocks]
58 [gdscript]
59 var tween = create_tween()
60 for sprite in get_children():
61 tween.tween_property(sprite, "position", Vector2(0, 0), 1.0)
62 [/gdscript]
63 [csharp]
64 Tween tween = CreateTween();
65 foreach (Node sprite in GetChildren())
66 tween.TweenProperty(sprite, "position", Vector2.Zero, 1.0f);
67 [/csharp]
68 [/codeblocks]
69 In the example above, all children of a node are moved one after another to position [code](0, 0)[/code].
70 You should avoid using more than one [Tween] per object's property. If two or more tweens animate one property at the same time, the last one created will take priority and assign the final value. If you want to interrupt and restart an animation, consider assigning the [Tween] to a variable:
71 [codeblocks]
72 [gdscript]
73 var tween
74 func animate():
75 if tween:
76 tween.kill() # Abort the previous animation.
77 tween = create_tween()
78 [/gdscript]
79 [csharp]
80 private Tween _tween;
81
82 public void Animate()
83 {
84 if (_tween != null)
85 _tween.Kill(); // Abort the previous animation
86 _tween = CreateTween();
87 }
88 [/csharp]
89 [/codeblocks]
90 Some [Tweener]s use transitions and eases. The first accepts a [enum 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 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 TransitionType] constants with [constant EASE_IN_OUT], and use the one that looks best.
91 [url=https://raw.githubusercontent.com/godotengine/godot-docs/master/img/tween_cheatsheet.webp]Tween easing and transition types cheatsheet[/url]
92 [b]Note:[/b] Tweens are not designed to be reused and trying to do so results in an undefined behavior. Create a new Tween for each animation and every time you replay an animation from start. Keep in mind that Tweens start immediately, so only create a Tween when you want to start animating.
93 [b]Note:[/b] The tween is processed after all of the nodes in the current frame, i.e. node's [method Node._process] method would be called before the tween (or [method Node._physics_process] depending on the value passed to [method set_process_mode]).
94 </description>
95 <tutorials>
96 </tutorials>
97 <methods>
98 <method name="bind_node">
99 <return type="Tween" />
100 <param index="0" name="node" type="Node" />
101 <description>
102 Binds this [Tween] with the given [param node]. [Tween]s are processed directly by the [SceneTree], so they run independently of the animated nodes. When you bind a [Node] with the [Tween], the [Tween] will halt the animation when the object is not inside tree and the [Tween] 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.
103 For a shorter way to create and bind a [Tween], you can use [method Node.create_tween].
104 </description>
105 </method>
106 <method name="chain">
107 <return type="Tween" />
108 <description>
109 Used to chain two [Tweener]s after [method set_parallel] is called with [code]true[/code].
110 [codeblocks]
111 [gdscript]
112 var tween = create_tween().set_parallel(true)
113 tween.tween_property(...)
114 tween.tween_property(...) # Will run parallelly with above.
115 tween.chain().tween_property(...) # Will run after two above are finished.
116 [/gdscript]
117 [csharp]
118 Tween tween = CreateTween().SetParallel(true);
119 tween.TweenProperty(...);
120 tween.TweenProperty(...); // Will run parallelly with above.
121 tween.Chain().TweenProperty(...); // Will run after two above are finished.
122 [/csharp]
123 [/codeblocks]
124 </description>
125 </method>
126 <method name="custom_step">
127 <return type="bool" />
128 <param index="0" name="delta" type="float" />
129 <description>
130 Processes the [Tween] by the given [param delta] value, in seconds. This is mostly useful for manual control when the [Tween] is paused. It can also be used to end the [Tween] animation immediately, by setting [param delta] longer than the whole duration of the [Tween] animation.
131 Returns [code]true[/code] if the [Tween] still has [Tweener]s that haven't finished.
132 </description>
133 </method>
134 <method name="get_loops_left" qualifiers="const">
135 <return type="int" />
136 <description>
137 Returns the number of remaining loops for this [Tween] (see [method set_loops]). A return value of [code]-1[/code] indicates an infinitely looping [Tween], and a return value of [code]0[/code] indicates that the [Tween] has already finished.
138 </description>
139 </method>
140 <method name="get_total_elapsed_time" qualifiers="const">
141 <return type="float" />
142 <description>
143 Returns the total time in seconds the [Tween] has been animating (i.e. the 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].
144 [b]Note:[/b] As it results from accumulating frame deltas, the time returned after the [Tween] has finished animating will be slightly greater than the actual [Tween] duration.
145 </description>
146 </method>
147 <method name="interpolate_value" qualifiers="static">
148 <return type="Variant" />
149 <param index="0" name="initial_value" type="Variant" />
150 <param index="1" name="delta_value" type="Variant" />
151 <param index="2" name="elapsed_time" type="float" />
152 <param index="3" name="duration" type="float" />
153 <param index="4" name="trans_type" type="int" enum="Tween.TransitionType" />
154 <param index="5" name="ease_type" type="int" enum="Tween.EaseType" />
155 <description>
156 This method can be used for manual interpolation of a value, when you don't want [Tween] to do animating for you. It's similar to [method @GlobalScope.lerp], but with support for custom transition and easing.
157 [param initial_value] is the starting value of the interpolation.
158 [param delta_value] is the change of the value in the interpolation, i.e. it's equal to [code]final_value - initial_value[/code].
159 [param elapsed_time] 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 [param duration], the interpolated value will be halfway between initial and final values. This value can also be greater than [param duration] or lower than 0, which will extrapolate the value.
160 [param duration] is the total time of the interpolation.
161 [b]Note:[/b] If [param duration] is equal to [code]0[/code], the method will always return the final value, regardless of [param elapsed_time] provided.
162 </description>
163 </method>
164 <method name="is_running">
165 <return type="bool" />
166 <description>
167 Returns whether the [Tween] is currently running, i.e. it wasn't paused and it's not finished.
168 </description>
169 </method>
170 <method name="is_valid">
171 <return type="bool" />
172 <description>
173 Returns whether the [Tween] is valid. A valid [Tween] is a [Tween] contained by the scene tree (i.e. the array from [method SceneTree.get_processed_tweens] will contain this [Tween]). A [Tween] might become invalid when it has finished tweening, is killed, or when created with [code]Tween.new()[/code]. Invalid [Tween]s can't have [Tweener]s appended.
174 </description>
175 </method>
176 <method name="kill">
177 <return type="void" />
178 <description>
179 Aborts all tweening operations and invalidates the [Tween].
180 </description>
181 </method>
182 <method name="parallel">
183 <return type="Tween" />
184 <description>
185 Makes the next [Tweener] run parallelly to the previous one.
186 [codeblocks]
187 [gdscript]
188 var tween = create_tween()
189 tween.tween_property(...)
190 tween.parallel().tween_property(...)
191 tween.parallel().tween_property(...)
192 [/gdscript]
193 [csharp]
194 Tween tween = CreateTween();
195 tween.TweenProperty(...);
196 tween.Parallel().TweenProperty(...);
197 tween.Parallel().TweenProperty(...);
198 [/csharp]
199 [/codeblocks]
200 All [Tweener]s in the example will run at the same time.
201 You can make the [Tween] parallel by default by using [method set_parallel].
202 </description>
203 </method>
204 <method name="pause">
205 <return type="void" />
206 <description>
207 Pauses the tweening. The animation can be resumed by using [method play].
208 [b]Note:[/b] If a Tween is paused and not bound to any node, it will exist indefinitely until manually started or invalidated. If you lose a reference to such Tween, you can retrieve it using [method SceneTree.get_processed_tweens].
209 </description>
210 </method>
211 <method name="play">
212 <return type="void" />
213 <description>
214 Resumes a paused or stopped [Tween].
215 </description>
216 </method>
217 <method name="set_ease">
218 <return type="Tween" />
219 <param index="0" name="ease" type="int" enum="Tween.EaseType" />
220 <description>
221 Sets the default ease type for [PropertyTweener]s and [MethodTweener]s appended after this method.
222 Before this method is called, the default ease type is [constant EASE_IN_OUT].
223 [codeblock]
224 var tween = create_tween()
225 tween.tween_property(self, "position", Vector2(300, 0), 0.5) # Uses EASE_IN_OUT.
226 tween.set_ease(Tween.EASE_IN)
227 tween.tween_property(self, "rotation_degrees", 45.0, 0.5) # Uses EASE_IN.
228 [/codeblock]
229 </description>
230 </method>
231 <method name="set_ignore_time_scale">
232 <return type="Tween" />
233 <param index="0" name="ignore" type="bool" default="true" />
234 <description>
235 If [param ignore] is [code]true[/code], the tween will ignore [member Engine.time_scale] and update with the real, elapsed time. This affects all [Tweener]s and their delays. Default value is [code]false[/code].
236 </description>
237 </method>
238 <method name="set_loops">
239 <return type="Tween" />
240 <param index="0" name="loops" type="int" default="0" />
241 <description>
242 Sets the number of times the tweening sequence will be repeated, i.e. [code]set_loops(2)[/code] will run the animation twice.
243 Calling this method without arguments will make the [Tween] run infinitely, until either it is killed with [method kill], the [Tween]'s bound node is freed, or all the animated objects have been freed (which makes further animation impossible).
244 [b]Warning:[/b] Make sure to always add some duration/delay when using infinite loops. To prevent the game freezing, 0-duration looped animations (e.g. a single [CallbackTweener] with no delay) are stopped after a small number of loops, which may produce unexpected results. If a [Tween]'s lifetime depends on some node, always use [method bind_node].
245 </description>
246 </method>
247 <method name="set_parallel">
248 <return type="Tween" />
249 <param index="0" name="parallel" type="bool" default="true" />
250 <description>
251 If [param parallel] is [code]true[/code], the [Tweener]s appended after this method will by default run simultaneously, as opposed to sequentially.
252 [b]Note:[/b] Just like with [method parallel], the tweener added right before this method will also be part of the parallel step.
253 [codeblock]
254 tween.tween_property(self, "position", Vector2(300, 0), 0.5)
255 tween.set_parallel()
256 tween.tween_property(self, "modulate", Color.GREEN, 0.5) # Runs together with the position tweener.
257 [/codeblock]
258 </description>
259 </method>
260 <method name="set_pause_mode">
261 <return type="Tween" />
262 <param index="0" name="mode" type="int" enum="Tween.TweenPauseMode" />
263 <description>
264 Determines the behavior of the [Tween] when the [SceneTree] is paused.
265 Default value is [constant TWEEN_PAUSE_BOUND].
266 </description>
267 </method>
268 <method name="set_process_mode">
269 <return type="Tween" />
270 <param index="0" name="mode" type="int" enum="Tween.TweenProcessMode" />
271 <description>
272 Determines whether the [Tween] should run after process frames (see [method Node._process]) or physics frames (see [method Node._physics_process]).
273 Default value is [constant TWEEN_PROCESS_IDLE].
274 </description>
275 </method>
276 <method name="set_speed_scale">
277 <return type="Tween" />
278 <param index="0" name="speed" type="float" />
279 <description>
280 Scales the speed of tweening. This affects all [Tweener]s and their delays.
281 </description>
282 </method>
283 <method name="set_trans">
284 <return type="Tween" />
285 <param index="0" name="trans" type="int" enum="Tween.TransitionType" />
286 <description>
287 Sets the default transition type for [PropertyTweener]s and [MethodTweener]s appended after this method.
288 Before this method is called, the default transition type is [constant TRANS_LINEAR].
289 [codeblock]
290 var tween = create_tween()
291 tween.tween_property(self, "position", Vector2(300, 0), 0.5) # Uses TRANS_LINEAR.
292 tween.set_trans(Tween.TRANS_SINE)
293 tween.tween_property(self, "rotation_degrees", 45.0, 0.5) # Uses TRANS_SINE.
294 [/codeblock]
295 </description>
296 </method>
297 <method name="stop">
298 <return type="void" />
299 <description>
300 Stops the tweening and resets the [Tween] to its initial state. This will not remove any appended [Tweener]s.
301 [b]Note:[/b] This does [i]not[/i] reset targets of [PropertyTweener]s to their values when the [Tween] first started.
302 [codeblock]
303 var tween = create_tween()
304
305 # Will move from 0 to 500 over 1 second.
306 position.x = 0.0
307 tween.tween_property(self, "position:x", 500, 1.0)
308
309 # Will be at (about) 250 when the timer finishes.
310 await get_tree().create_timer(0.5).timeout
311
312 # Will now move from (about) 250 to 500 over 1 second,
313 # thus at half the speed as before.
314 tween.stop()
315 tween.play()
316 [/codeblock]
317 [b]Note:[/b] If a Tween is stopped and not bound to any node, it will exist indefinitely until manually started or invalidated. If you lose a reference to such Tween, you can retrieve it using [method SceneTree.get_processed_tweens].
318 </description>
319 </method>
320 <method name="tween_callback">
321 <return type="CallbackTweener" />
322 <param index="0" name="callback" type="Callable" />
323 <description>
324 Creates and appends a [CallbackTweener]. This method can be used to call an arbitrary method in any object. Use [method Callable.bind] to bind additional arguments for the call.
325 [b]Example:[/b] Object that keeps shooting every 1 second:
326 [codeblocks]
327 [gdscript]
328 var tween = get_tree().create_tween().set_loops()
329 tween.tween_callback(shoot).set_delay(1.0)
330 [/gdscript]
331 [csharp]
332 Tween tween = GetTree().CreateTween().SetLoops();
333 tween.TweenCallback(Callable.From(Shoot)).SetDelay(1.0f);
334 [/csharp]
335 [/codeblocks]
336 [b]Example:[/b] Turning a sprite red and then blue, with 2 second delay:
337 [codeblocks]
338 [gdscript]
339 var tween = get_tree().create_tween()
340 tween.tween_callback($Sprite.set_modulate.bind(Color.RED)).set_delay(2)
341 tween.tween_callback($Sprite.set_modulate.bind(Color.BLUE)).set_delay(2)
342 [/gdscript]
343 [csharp]
344 Tween tween = GetTree().CreateTween();
345 Sprite2D sprite = GetNode&lt;Sprite2D&gt;("Sprite");
346 tween.TweenCallback(Callable.From(() =&gt; sprite.Modulate = Colors.Red)).SetDelay(2.0f);
347 tween.TweenCallback(Callable.From(() =&gt; sprite.Modulate = Colors.Blue)).SetDelay(2.0f);
348 [/csharp]
349 [/codeblocks]
350 </description>
351 </method>
352 <method name="tween_interval">
353 <return type="IntervalTweener" />
354 <param index="0" name="time" type="float" />
355 <description>
356 Creates and appends an [IntervalTweener]. This method can be used to create delays in the tween animation, as an alternative to using the delay in other [Tweener]s, or when there's no animation (in which case the [Tween] acts as a timer). [param time] is the length of the interval, in seconds.
357 [b]Example:[/b] Creating an interval in code execution:
358 [codeblocks]
359 [gdscript]
360 # ... some code
361 await create_tween().tween_interval(2).finished
362 # ... more code
363 [/gdscript]
364 [csharp]
365 // ... some code
366 await ToSignal(CreateTween().TweenInterval(2.0f), Tween.SignalName.Finished);
367 // ... more code
368 [/csharp]
369 [/codeblocks]
370 [b]Example:[/b] Creating an object that moves back and forth and jumps every few seconds:
371 [codeblocks]
372 [gdscript]
373 var tween = create_tween().set_loops()
374 tween.tween_property($Sprite, "position:x", 200.0, 1.0).as_relative()
375 tween.tween_callback(jump)
376 tween.tween_interval(2)
377 tween.tween_property($Sprite, "position:x", -200.0, 1.0).as_relative()
378 tween.tween_callback(jump)
379 tween.tween_interval(2)
380 [/gdscript]
381 [csharp]
382 Tween tween = CreateTween().SetLoops();
383 tween.TweenProperty(GetNode("Sprite"), "position:x", 200.0f, 1.0f).AsRelative();
384 tween.TweenCallback(Callable.From(Jump));
385 tween.TweenInterval(2.0f);
386 tween.TweenProperty(GetNode("Sprite"), "position:x", -200.0f, 1.0f).AsRelative();
387 tween.TweenCallback(Callable.From(Jump));
388 tween.TweenInterval(2.0f);
389 [/csharp]
390 [/codeblocks]
391 </description>
392 </method>
393 <method name="tween_method">
394 <return type="MethodTweener" />
395 <param index="0" name="method" type="Callable" />
396 <param index="1" name="from" type="Variant" />
397 <param index="2" name="to" type="Variant" />
398 <param index="3" name="duration" type="float" />
399 <description>
400 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 [param from] and [param to] over the time specified by [param duration], in seconds. Use [method Callable.bind] 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.
401 [b]Example:[/b] Making a 3D object look from one point to another point:
402 [codeblocks]
403 [gdscript]
404 var tween = create_tween()
405 tween.tween_method(look_at.bind(Vector3.UP), Vector3(-1, 0, -1), Vector3(1, 0, -1), 1.0) # The look_at() method takes up vector as second argument.
406 [/gdscript]
407 [csharp]
408 Tween tween = CreateTween();
409 tween.TweenMethod(Callable.From((Vector3 target) =&gt; LookAt(target, Vector3.Up)), new Vector3(-1.0f, 0.0f, -1.0f), new Vector3(1.0f, 0.0f, -1.0f), 1.0f); // Use lambdas to bind additional arguments for the call.
410 [/csharp]
411 [/codeblocks]
412 [b]Example:[/b] Setting the text of a [Label], using an intermediate method and after a delay:
413 [codeblocks]
414 [gdscript]
415 func _ready():
416 var tween = create_tween()
417 tween.tween_method(set_label_text, 0, 10, 1.0).set_delay(1.0)
418
419 func set_label_text(value: int):
420 $Label.text = "Counting " + str(value)
421 [/gdscript]
422 [csharp]
423 public override void _Ready()
424 {
425 base._Ready();
426
427 Tween tween = CreateTween();
428 tween.TweenMethod(Callable.From&lt;int&gt;(SetLabelText), 0.0f, 10.0f, 1.0f).SetDelay(1.0f);
429 }
430
431 private void SetLabelText(int value)
432 {
433 GetNode&lt;Label&gt;("Label").Text = $"Counting {value}";
434 }
435 [/csharp]
436 [/codeblocks]
437 </description>
438 </method>
439 <method name="tween_property">
440 <return type="PropertyTweener" />
441 <param index="0" name="object" type="Object" />
442 <param index="1" name="property" type="NodePath" />
443 <param index="2" name="final_val" type="Variant" />
444 <param index="3" name="duration" type="float" />
445 <description>
446 Creates and appends a [PropertyTweener]. This method tweens a [param property] of an [param object] between an initial value and [param final_val] in a span of time equal to [param duration], in seconds. The initial value by default is the property's value at the time the tweening of the [PropertyTweener] starts.
447 [codeblocks]
448 [gdscript]
449 var tween = create_tween()
450 tween.tween_property($Sprite, "position", Vector2(100, 200), 1.0)
451 tween.tween_property($Sprite, "position", Vector2(200, 300), 1.0)
452 [/gdscript]
453 [csharp]
454 Tween tween = CreateTween();
455 tween.TweenProperty(GetNode("Sprite"), "position", new Vector2(100.0f, 200.0f), 1.0f);
456 tween.TweenProperty(GetNode("Sprite"), "position", new Vector2(200.0f, 300.0f), 1.0f);
457 [/csharp]
458 [/codeblocks]
459 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.
460 [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.
461 [b]Example:[/b] Moving an object twice from the same position, with different transition types:
462 [codeblocks]
463 [gdscript]
464 var tween = create_tween()
465 tween.tween_property($Sprite, "position", Vector2.RIGHT * 300, 1.0).as_relative().set_trans(Tween.TRANS_SINE)
466 tween.tween_property($Sprite, "position", Vector2.RIGHT * 300, 1.0).as_relative().from_current().set_trans(Tween.TRANS_EXPO)
467 [/gdscript]
468 [csharp]
469 Tween tween = CreateTween();
470 tween.TweenProperty(GetNode("Sprite"), "position", Vector2.Right * 300.0f, 1.0f).AsRelative().SetTrans(Tween.TransitionType.Sine);
471 tween.TweenProperty(GetNode("Sprite"), "position", Vector2.Right * 300.0f, 1.0f).AsRelative().FromCurrent().SetTrans(Tween.TransitionType.Expo);
472 [/csharp]
473 [/codeblocks]
474 </description>
475 </method>
476 <method name="tween_subtween">
477 <return type="SubtweenTweener" />
478 <param index="0" name="subtween" type="Tween" />
479 <description>
480 Creates and appends a [SubtweenTweener]. This method can be used to nest [param subtween] within this [Tween], allowing for the creation of more complex and composable sequences.
481 [codeblock]
482 # Subtween will rotate the object.
483 var subtween = create_tween()
484 subtween.tween_property(self, "rotation_degrees", 45.0, 1.0)
485 subtween.tween_property(self, "rotation_degrees", 0.0, 1.0)
486
487 # Parent tween will execute the subtween as one of its steps.
488 var tween = create_tween()
489 tween.tween_property(self, "position:x", 500, 3.0)
490 tween.tween_subtween(subtween)
491 tween.tween_property(self, "position:x", 300, 2.0)
492 [/codeblock]
493 [b]Note:[/b] The methods [method pause], [method stop], and [method set_loops] can cause the parent [Tween] to get stuck on the subtween step; see the documentation for those methods for more information.
494 [b]Note:[/b] The pause and process modes set by [method set_pause_mode] and [method set_process_mode] on [param subtween] will be overridden by the parent [Tween]'s settings.
495 </description>
496 </method>
497 </methods>
498 <signals>
499 <signal name="finished">
500 <description>
501 Emitted when the [Tween] has finished all tweening. Never emitted when the [Tween] is set to infinite looping (see [method set_loops]).
502 </description>
503 </signal>
504 <signal name="loop_finished">
505 <param index="0" name="loop_count" type="int" />
506 <description>
507 Emitted when a full loop is complete (see [method set_loops]), providing the loop index. This signal is not emitted after the final loop, use [signal finished] instead for this case.
508 </description>
509 </signal>
510 <signal name="step_finished">
511 <param index="0" name="idx" type="int" />
512 <description>
513 Emitted when one step of the [Tween] is complete, providing the step index. One step is either a single [Tweener] or a group of [Tweener]s running in parallel.
514 </description>
515 </signal>
516 </signals>
517 <constants>
518 <constant name="TWEEN_PROCESS_PHYSICS" value="0" enum="TweenProcessMode">
519 The [Tween] updates after each physics frame (see [method Node._physics_process]).
520 </constant>
521 <constant name="TWEEN_PROCESS_IDLE" value="1" enum="TweenProcessMode">
522 The [Tween] updates after each process frame (see [method Node._process]).
523 </constant>
524 <constant name="TWEEN_PAUSE_BOUND" value="0" enum="TweenPauseMode">
525 If the [Tween] has a bound node, it will process when that node can process (see [member Node.process_mode]). Otherwise it's the same as [constant TWEEN_PAUSE_STOP].
526 </constant>
527 <constant name="TWEEN_PAUSE_STOP" value="1" enum="TweenPauseMode">
528 If [SceneTree] is paused, the [Tween] will also pause.
529 </constant>
530 <constant name="TWEEN_PAUSE_PROCESS" value="2" enum="TweenPauseMode">
531 The [Tween] will process regardless of whether [SceneTree] is paused.
532 </constant>
533 <constant name="TRANS_LINEAR" value="0" enum="TransitionType">
534 The animation is interpolated linearly.
535 </constant>
536 <constant name="TRANS_SINE" value="1" enum="TransitionType">
537 The animation is interpolated using a sine function.
538 </constant>
539 <constant name="TRANS_QUINT" value="2" enum="TransitionType">
540 The animation is interpolated with a quintic (to the power of 5) function.
541 </constant>
542 <constant name="TRANS_QUART" value="3" enum="TransitionType">
543 The animation is interpolated with a quartic (to the power of 4) function.
544 </constant>
545 <constant name="TRANS_QUAD" value="4" enum="TransitionType">
546 The animation is interpolated with a quadratic (to the power of 2) function.
547 </constant>
548 <constant name="TRANS_EXPO" value="5" enum="TransitionType">
549 The animation is interpolated with an exponential (to the power of x) function.
550 </constant>
551 <constant name="TRANS_ELASTIC" value="6" enum="TransitionType">
552 The animation is interpolated with elasticity, wiggling around the edges.
553 </constant>
554 <constant name="TRANS_CUBIC" value="7" enum="TransitionType">
555 The animation is interpolated with a cubic (to the power of 3) function.
556 </constant>
557 <constant name="TRANS_CIRC" value="8" enum="TransitionType">
558 The animation is interpolated with a function using square roots.
559 </constant>
560 <constant name="TRANS_BOUNCE" value="9" enum="TransitionType">
561 The animation is interpolated by bouncing at the end.
562 </constant>
563 <constant name="TRANS_BACK" value="10" enum="TransitionType">
564 The animation is interpolated backing out at ends.
565 </constant>
566 <constant name="TRANS_SPRING" value="11" enum="TransitionType">
567 The animation is interpolated like a spring towards the end.
568 </constant>
569 <constant name="EASE_IN" value="0" enum="EaseType">
570 The interpolation starts slowly and speeds up towards the end.
571 </constant>
572 <constant name="EASE_OUT" value="1" enum="EaseType">
573 The interpolation starts quickly and slows down towards the end.
574 </constant>
575 <constant name="EASE_IN_OUT" value="2" enum="EaseType">
576 A combination of [constant EASE_IN] and [constant EASE_OUT]. The interpolation is slowest at both ends.
577 </constant>
578 <constant name="EASE_OUT_IN" value="3" enum="EaseType">
579 A combination of [constant EASE_IN] and [constant EASE_OUT]. The interpolation is fastest at both ends.
580 </constant>
581 </constants>
582 </class>