Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/doc/classes/AnimationPlayer.xml
20803 views
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<class name="AnimationPlayer" inherits="AnimationMixer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3
<brief_description>
4
A node used for animation playback.
5
</brief_description>
6
<description>
7
An animation player is used for general-purpose playback of animations. It contains a dictionary of [AnimationLibrary] resources and custom blend times between animation transitions.
8
Some methods and properties use a single key to reference an animation directly. These keys are formatted as the key for the library, followed by a forward slash, then the key for the animation within the library, for example [code]"movement/run"[/code]. If the library's key is an empty string (known as the default library), the forward slash is omitted, being the same key used by the library.
9
[AnimationPlayer] is better-suited than [Tween] for more complex animations, for example ones with non-trivial timings. It can also be used over [Tween] if the animation track editor is more convenient than doing it in code.
10
Updating the target properties of animations occurs at the process frame.
11
</description>
12
<tutorials>
13
<link title="2D Sprite animation">$DOCS_URL/tutorials/2d/2d_sprite_animation.html</link>
14
<link title="Animation documentation index">$DOCS_URL/tutorials/animation/index.html</link>
15
<link title="Third Person Shooter (TPS) Demo">https://godotengine.org/asset-library/asset/2710</link>
16
</tutorials>
17
<methods>
18
<method name="animation_get_next" qualifiers="const">
19
<return type="StringName" />
20
<param index="0" name="animation_from" type="StringName" />
21
<description>
22
Returns the key of the animation which is queued to play after the [param animation_from] animation.
23
</description>
24
</method>
25
<method name="animation_set_next">
26
<return type="void" />
27
<param index="0" name="animation_from" type="StringName" />
28
<param index="1" name="animation_to" type="StringName" />
29
<description>
30
Triggers the [param animation_to] animation when the [param animation_from] animation completes.
31
</description>
32
</method>
33
<method name="clear_queue">
34
<return type="void" />
35
<description>
36
Clears all queued, unplayed animations.
37
</description>
38
</method>
39
<method name="get_blend_time" qualifiers="const">
40
<return type="float" />
41
<param index="0" name="animation_from" type="StringName" />
42
<param index="1" name="animation_to" type="StringName" />
43
<description>
44
Returns the blend time (in seconds) between two animations, referenced by their keys.
45
</description>
46
</method>
47
<method name="get_method_call_mode" qualifiers="const" deprecated="Use [member AnimationMixer.callback_mode_method] instead.">
48
<return type="int" enum="AnimationPlayer.AnimationMethodCallMode" />
49
<description>
50
Returns the call mode used for "Call Method" tracks.
51
</description>
52
</method>
53
<method name="get_playing_speed" qualifiers="const">
54
<return type="float" />
55
<description>
56
Returns the actual playing speed of current animation or [code]0[/code] if not playing. This speed is the [member speed_scale] property multiplied by [code]custom_speed[/code] argument specified when calling the [method play] method.
57
Returns a negative value if the current animation is playing backwards.
58
</description>
59
</method>
60
<method name="get_process_callback" qualifiers="const" deprecated="Use [member AnimationMixer.callback_mode_process] instead.">
61
<return type="int" enum="AnimationPlayer.AnimationProcessCallback" />
62
<description>
63
Returns the process notification in which to update animations.
64
</description>
65
</method>
66
<method name="get_queue">
67
<return type="StringName[]" />
68
<description>
69
Returns a list of the animation keys that are currently queued to play.
70
</description>
71
</method>
72
<method name="get_root" qualifiers="const" deprecated="Use [member AnimationMixer.root_node] instead.">
73
<return type="NodePath" />
74
<description>
75
Returns the node which node path references will travel from.
76
</description>
77
</method>
78
<method name="get_section_end_time" qualifiers="const">
79
<return type="float" />
80
<description>
81
Returns the end time of the section currently being played.
82
</description>
83
</method>
84
<method name="get_section_start_time" qualifiers="const">
85
<return type="float" />
86
<description>
87
Returns the start time of the section currently being played.
88
</description>
89
</method>
90
<method name="has_section" qualifiers="const">
91
<return type="bool" />
92
<description>
93
Returns [code]true[/code] if an animation is currently playing with a section.
94
</description>
95
</method>
96
<method name="is_animation_active" qualifiers="const">
97
<return type="bool" />
98
<description>
99
Returns [code]true[/code] if the an animation is currently active. An animation is active if it was played by calling [method play] and was not finished yet, or was stopped by calling [method stop].
100
This can be used to check whether an animation is currently paused or stopped.
101
[codeblock]
102
var is_paused = not is_playing() and is_animation_active()
103
var is_stopped = not is_playing() and not is_animation_active()
104
[/codeblock]
105
</description>
106
</method>
107
<method name="is_playing" qualifiers="const">
108
<return type="bool" />
109
<description>
110
Returns [code]true[/code] if an animation is currently playing (even if [member speed_scale] and/or [code]custom_speed[/code] are [code]0[/code]).
111
</description>
112
</method>
113
<method name="pause">
114
<return type="void" />
115
<description>
116
Pauses the currently playing animation. The [member current_animation_position] will be kept and calling [method play] or [method play_backwards] without arguments or with the same animation name as [member assigned_animation] will resume the animation.
117
See also [method stop].
118
</description>
119
</method>
120
<method name="play">
121
<return type="void" />
122
<param index="0" name="name" type="StringName" default="&amp;&quot;&quot;" />
123
<param index="1" name="custom_blend" type="float" default="-1" />
124
<param index="2" name="custom_speed" type="float" default="1.0" />
125
<param index="3" name="from_end" type="bool" default="false" />
126
<description>
127
Plays the animation with key [param name]. Custom blend times and speed can be set.
128
The [param from_end] option only affects when switching to a new animation track, or if the same track but at the start or end. It does not affect resuming playback that was paused in the middle of an animation. If [param custom_speed] is negative and [param from_end] is [code]true[/code], the animation will play backwards (which is equivalent to calling [method play_backwards]).
129
The [AnimationPlayer] keeps track of its current or last played animation with [member assigned_animation]. If this method is called with that same animation [param name], or with no [param name] parameter, the assigned animation will resume playing if it was paused.
130
[b]Note:[/b] The animation will be updated the next time the [AnimationPlayer] is processed. If other variables are updated at the same time this is called, they may be updated too early. To perform the update immediately, call [code]advance(0)[/code].
131
</description>
132
</method>
133
<method name="play_backwards">
134
<return type="void" />
135
<param index="0" name="name" type="StringName" default="&amp;&quot;&quot;" />
136
<param index="1" name="custom_blend" type="float" default="-1" />
137
<description>
138
Plays the animation with key [param name] in reverse.
139
This method is a shorthand for [method play] with [code]custom_speed = -1.0[/code] and [code]from_end = true[/code], so see its description for more information.
140
</description>
141
</method>
142
<method name="play_section">
143
<return type="void" />
144
<param index="0" name="name" type="StringName" default="&amp;&quot;&quot;" />
145
<param index="1" name="start_time" type="float" default="-1" />
146
<param index="2" name="end_time" type="float" default="-1" />
147
<param index="3" name="custom_blend" type="float" default="-1" />
148
<param index="4" name="custom_speed" type="float" default="1.0" />
149
<param index="5" name="from_end" type="bool" default="false" />
150
<description>
151
Plays the animation with key [param name] and the section starting from [param start_time] and ending on [param end_time]. See also [method play].
152
Setting [param start_time] to a value outside the range of the animation means the start of the animation will be used instead, and setting [param end_time] to a value outside the range of the animation means the end of the animation will be used instead. [param start_time] cannot be equal to [param end_time].
153
</description>
154
</method>
155
<method name="play_section_backwards">
156
<return type="void" />
157
<param index="0" name="name" type="StringName" default="&amp;&quot;&quot;" />
158
<param index="1" name="start_time" type="float" default="-1" />
159
<param index="2" name="end_time" type="float" default="-1" />
160
<param index="3" name="custom_blend" type="float" default="-1" />
161
<description>
162
Plays the animation with key [param name] and the section starting from [param start_time] and ending on [param end_time] in reverse.
163
This method is a shorthand for [method play_section] with [code]custom_speed = -1.0[/code] and [code]from_end = true[/code], see its description for more information.
164
</description>
165
</method>
166
<method name="play_section_with_markers">
167
<return type="void" />
168
<param index="0" name="name" type="StringName" default="&amp;&quot;&quot;" />
169
<param index="1" name="start_marker" type="StringName" default="&amp;&quot;&quot;" />
170
<param index="2" name="end_marker" type="StringName" default="&amp;&quot;&quot;" />
171
<param index="3" name="custom_blend" type="float" default="-1" />
172
<param index="4" name="custom_speed" type="float" default="1.0" />
173
<param index="5" name="from_end" type="bool" default="false" />
174
<description>
175
Plays the animation with key [param name] and the section starting from [param start_marker] and ending on [param end_marker].
176
If the start marker is empty, the section starts from the beginning of the animation. If the end marker is empty, the section ends on the end of the animation. See also [method play].
177
</description>
178
</method>
179
<method name="play_section_with_markers_backwards">
180
<return type="void" />
181
<param index="0" name="name" type="StringName" default="&amp;&quot;&quot;" />
182
<param index="1" name="start_marker" type="StringName" default="&amp;&quot;&quot;" />
183
<param index="2" name="end_marker" type="StringName" default="&amp;&quot;&quot;" />
184
<param index="3" name="custom_blend" type="float" default="-1" />
185
<description>
186
Plays the animation with key [param name] and the section starting from [param start_marker] and ending on [param end_marker] in reverse.
187
This method is a shorthand for [method play_section_with_markers] with [code]custom_speed = -1.0[/code] and [code]from_end = true[/code], see its description for more information.
188
</description>
189
</method>
190
<method name="play_with_capture">
191
<return type="void" />
192
<param index="0" name="name" type="StringName" default="&amp;&quot;&quot;" />
193
<param index="1" name="duration" type="float" default="-1.0" />
194
<param index="2" name="custom_blend" type="float" default="-1" />
195
<param index="3" name="custom_speed" type="float" default="1.0" />
196
<param index="4" name="from_end" type="bool" default="false" />
197
<param index="5" name="trans_type" type="int" enum="Tween.TransitionType" default="0" />
198
<param index="6" name="ease_type" type="int" enum="Tween.EaseType" default="0" />
199
<description>
200
See also [method AnimationMixer.capture].
201
You can use this method to use more detailed options for capture than those performed by [member playback_auto_capture]. When [member playback_auto_capture] is [code]false[/code], this method is almost the same as the following:
202
[codeblock]
203
capture(name, duration, trans_type, ease_type)
204
play(name, custom_blend, custom_speed, from_end)
205
[/codeblock]
206
If [param name] is blank, it specifies [member assigned_animation].
207
If [param duration] is a negative value, the duration is set to the interval between the current position and the first key, when [param from_end] is [code]true[/code], uses the interval between the current position and the last key instead.
208
[b]Note:[/b] The [param duration] takes [member speed_scale] into account, but [param custom_speed] does not, because the capture cache is interpolated with the blend result and the result may contain multiple animations.
209
</description>
210
</method>
211
<method name="queue">
212
<return type="void" />
213
<param index="0" name="name" type="StringName" />
214
<description>
215
Queues an animation for playback once the current animation and all previously queued animations are done.
216
[b]Note:[/b] If a looped animation is currently playing, the queued animation will never play unless the looped animation is stopped somehow.
217
</description>
218
</method>
219
<method name="reset_section">
220
<return type="void" />
221
<description>
222
Resets the current section. Does nothing if a section has not been set.
223
</description>
224
</method>
225
<method name="seek">
226
<return type="void" />
227
<param index="0" name="seconds" type="float" />
228
<param index="1" name="update" type="bool" default="false" />
229
<param index="2" name="update_only" type="bool" default="false" />
230
<description>
231
Seeks the animation to the [param seconds] point in time (in seconds). If [param update] is [code]true[/code], the animation updates too, otherwise it updates at process time. Events between the current frame and [param seconds] are skipped.
232
If [param update_only] is [code]true[/code], the method / audio / animation playback tracks will not be processed.
233
[b]Note:[/b] Seeking to the end of the animation doesn't emit [signal AnimationMixer.animation_finished]. If you want to skip animation and emit the signal, use [method AnimationMixer.advance].
234
</description>
235
</method>
236
<method name="set_blend_time">
237
<return type="void" />
238
<param index="0" name="animation_from" type="StringName" />
239
<param index="1" name="animation_to" type="StringName" />
240
<param index="2" name="sec" type="float" />
241
<description>
242
Specifies a blend time (in seconds) between two animations, referenced by their keys.
243
</description>
244
</method>
245
<method name="set_method_call_mode" deprecated="Use [member AnimationMixer.callback_mode_method] instead.">
246
<return type="void" />
247
<param index="0" name="mode" type="int" enum="AnimationPlayer.AnimationMethodCallMode" />
248
<description>
249
Sets the call mode used for "Call Method" tracks.
250
</description>
251
</method>
252
<method name="set_process_callback" deprecated="Use [member AnimationMixer.callback_mode_process] instead.">
253
<return type="void" />
254
<param index="0" name="mode" type="int" enum="AnimationPlayer.AnimationProcessCallback" />
255
<description>
256
Sets the process notification in which to update animations.
257
</description>
258
</method>
259
<method name="set_root" deprecated="Use [member AnimationMixer.root_node] instead.">
260
<return type="void" />
261
<param index="0" name="path" type="NodePath" />
262
<description>
263
Sets the node which node path references will travel from.
264
</description>
265
</method>
266
<method name="set_section">
267
<return type="void" />
268
<param index="0" name="start_time" type="float" default="-1" />
269
<param index="1" name="end_time" type="float" default="-1" />
270
<description>
271
Changes the start and end times of the section being played. The current playback position will be clamped within the new section. See also [method play_section].
272
</description>
273
</method>
274
<method name="set_section_with_markers">
275
<return type="void" />
276
<param index="0" name="start_marker" type="StringName" default="&amp;&quot;&quot;" />
277
<param index="1" name="end_marker" type="StringName" default="&amp;&quot;&quot;" />
278
<description>
279
Changes the start and end markers of the section being played. The current playback position will be clamped within the new section. See also [method play_section_with_markers].
280
If the argument is empty, the section uses the beginning or end of the animation. If both are empty, it means that the section is not set.
281
</description>
282
</method>
283
<method name="stop">
284
<return type="void" />
285
<param index="0" name="keep_state" type="bool" default="false" />
286
<description>
287
Stops the currently playing animation. The animation position is reset to [code]0[/code] and the [code]custom_speed[/code] is reset to [code]1.0[/code]. See also [method pause].
288
If [param keep_state] is [code]true[/code], the animation state is not updated visually.
289
[b]Note:[/b] The method / audio / animation playback tracks will not be processed by this method.
290
</description>
291
</method>
292
</methods>
293
<members>
294
<member name="assigned_animation" type="StringName" setter="set_assigned_animation" getter="get_assigned_animation">
295
If playing, the current animation's key, otherwise, the animation last played. When set, this changes the animation, but will not play it unless already playing. See also [member current_animation].
296
</member>
297
<member name="autoplay" type="StringName" setter="set_autoplay" getter="get_autoplay" default="&amp;&quot;&quot;">
298
The key of the animation to play when the scene loads.
299
</member>
300
<member name="current_animation" type="StringName" setter="set_current_animation" getter="get_current_animation" default="&amp;&quot;&quot;">
301
The key of the currently playing animation. If no animation is playing, the property's value is an empty string. Changing this value does not restart the animation. See [method play] for more information on playing animations.
302
[b]Note:[/b] While this property appears in the Inspector, it's not meant to be edited, and it's not saved in the scene. This property is mainly used to get the currently playing animation, and internally for animation playback tracks. For more information, see [Animation].
303
</member>
304
<member name="current_animation_length" type="float" setter="" getter="get_current_animation_length">
305
The length (in seconds) of the currently playing animation.
306
</member>
307
<member name="current_animation_position" type="float" setter="" getter="get_current_animation_position">
308
The position (in seconds) of the currently playing animation.
309
</member>
310
<member name="movie_quit_on_finish" type="bool" setter="set_movie_quit_on_finish_enabled" getter="is_movie_quit_on_finish_enabled" default="false">
311
If [code]true[/code] and the engine is running in Movie Maker mode (see [MovieWriter]), exits the engine with [method SceneTree.quit] as soon as an animation is done playing in this [AnimationPlayer]. A message is printed when the engine quits for this reason.
312
[b]Note:[/b] This obeys the same logic as the [signal AnimationMixer.animation_finished] signal, so it will not quit the engine if the animation is set to be looping.
313
</member>
314
<member name="playback_auto_capture" type="bool" setter="set_auto_capture" getter="is_auto_capture" default="true">
315
If [code]true[/code], performs [method AnimationMixer.capture] before playback automatically. This means just [method play_with_capture] is executed with default arguments instead of [method play].
316
[b]Note:[/b] Capture interpolation is only performed if the animation contains a capture track. See also [constant Animation.UPDATE_CAPTURE].
317
</member>
318
<member name="playback_auto_capture_duration" type="float" setter="set_auto_capture_duration" getter="get_auto_capture_duration" default="-1.0">
319
See also [method play_with_capture] and [method AnimationMixer.capture].
320
If [member playback_auto_capture_duration] is negative value, the duration is set to the interval between the current position and the first key.
321
</member>
322
<member name="playback_auto_capture_ease_type" type="int" setter="set_auto_capture_ease_type" getter="get_auto_capture_ease_type" enum="Tween.EaseType" default="0">
323
The ease type of the capture interpolation. See also [enum Tween.EaseType].
324
</member>
325
<member name="playback_auto_capture_transition_type" type="int" setter="set_auto_capture_transition_type" getter="get_auto_capture_transition_type" enum="Tween.TransitionType" default="0">
326
The transition type of the capture interpolation. See also [enum Tween.TransitionType].
327
</member>
328
<member name="playback_default_blend_time" type="float" setter="set_default_blend_time" getter="get_default_blend_time" default="0.0">
329
The default time in which to blend animations. Ranges from 0 to 4096 with 0.01 precision.
330
</member>
331
<member name="speed_scale" type="float" setter="set_speed_scale" getter="get_speed_scale" default="1.0">
332
The speed scaling ratio. For example, if this value is [code]1[/code], then the animation plays at normal speed. If it's [code]0.5[/code], then it plays at half speed. If it's [code]2[/code], then it plays at double speed.
333
If set to a negative value, the animation is played in reverse. If set to [code]0[/code], the animation will not advance.
334
</member>
335
</members>
336
<signals>
337
<signal name="animation_changed">
338
<param index="0" name="old_name" type="StringName" />
339
<param index="1" name="new_name" type="StringName" />
340
<description>
341
Emitted when a queued animation plays after the previous animation finished. See also [method AnimationPlayer.queue].
342
[b]Note:[/b] The signal is not emitted when the animation is changed via [method AnimationPlayer.play] or by an [AnimationTree].
343
</description>
344
</signal>
345
<signal name="current_animation_changed">
346
<param index="0" name="name" type="StringName" />
347
<description>
348
Emitted when [member current_animation] changes.
349
</description>
350
</signal>
351
</signals>
352
<constants>
353
<constant name="ANIMATION_PROCESS_PHYSICS" value="0" enum="AnimationProcessCallback" deprecated="See [constant AnimationMixer.ANIMATION_CALLBACK_MODE_PROCESS_PHYSICS].">
354
</constant>
355
<constant name="ANIMATION_PROCESS_IDLE" value="1" enum="AnimationProcessCallback" deprecated="See [constant AnimationMixer.ANIMATION_CALLBACK_MODE_PROCESS_IDLE].">
356
</constant>
357
<constant name="ANIMATION_PROCESS_MANUAL" value="2" enum="AnimationProcessCallback" deprecated="See [constant AnimationMixer.ANIMATION_CALLBACK_MODE_PROCESS_MANUAL].">
358
</constant>
359
<constant name="ANIMATION_METHOD_CALL_DEFERRED" value="0" enum="AnimationMethodCallMode" deprecated="See [constant AnimationMixer.ANIMATION_CALLBACK_MODE_METHOD_DEFERRED].">
360
</constant>
361
<constant name="ANIMATION_METHOD_CALL_IMMEDIATE" value="1" enum="AnimationMethodCallMode" deprecated="See [constant AnimationMixer.ANIMATION_CALLBACK_MODE_METHOD_IMMEDIATE].">
362
</constant>
363
</constants>
364
</class>
365
366