Animation
Inherits: Resource < Reference < Object Contains data used to animate everything in the engine.
Description
An Animation resource contains data used to animate everything in the engine. Animations are divided into tracks, and each track must be linked to a node. The state of that node can be changed through time, by adding timed keys (events) to the track.
# This creates an animation that makes the node "Enemy" move to the right by# 100 pixels in 0.5 seconds.var animation = Animation.new()var track_index = animation.add_track(Animation.TYPE_VALUE)animation.track_set_path(track_index, "Enemy:position:x")animation.track_insert_key(track_index, 0.0, 0)animation.track_insert_key(track_index, 0.5, 100)
AnimationPlayer or AnimationTreePlayer to be played back. Animation tracks have different types, each with its own set of dedicated methods. Check TrackType to see available types.
Tutorials
- Animation
Properties
Methods
Signals
- tracks_changed ( )
Emitted when there’s a change in the list of tracks, e.g. tracks are added, moved or have changed paths.
Enumerations
TrackType: - TYPE_VALUE = 0 —- Value tracks set values in node properties, but only those which can be Interpolated.
- TYPE_TRANSFORM = 1 —- Transform tracks are used to change node local transforms or skeleton pose bones. Transitions are interpolated.
- TYPE_METHOD = 2 —- Method tracks call functions with given arguments per key.
- TYPE_BEZIER = 3 —- Bezier tracks are used to interpolate a value using custom curves. They can also be used to animate sub-properties of vectors and colors (e.g. alpha value of a Color).
- TYPE_AUDIO = 4 —- Audio tracks are used to play an audio stream with either type of AudioStreamPlayer. The stream can be trimmed and previewed in the animation.
- TYPE_ANIMATION = 5 —- Animation tracks play animations in other AnimationPlayer nodes.
InterpolationType:
- INTERPOLATION_NEAREST = 0 —- No interpolation (nearest value).
- INTERPOLATION_LINEAR = 1 —- Linear interpolation.
- INTERPOLATION_CUBIC = 2 —- Cubic interpolation.
UpdateMode:
- UPDATE_CONTINUOUS = 0 —- Update between keyframes.
- UPDATE_DISCRETE = 1 —- Update at the keyframes and hold the value.
- UPDATE_TRIGGER = 2 —- Update at the keyframes.
- UPDATE_CAPTURE = 3 —- Same as linear interpolation, but also interpolates from the current value (i.e. dynamically at runtime) if the first key isn’t at 0 seconds.
Property Descriptions
- float length The total length of the animation (in seconds). Note: Length is not delimited by the last key, as this one may be before or after the end to ensure correct interpolation and looping.
- bool loop A flag indicating that the animation must loop. This is used for correct interpolation of animation cycles, and for hinting the player that it must restart the animation.
- float step
The animation step value.
Method Descriptions
- int add_track ( TrackType type, int at_position=-1 ) Adds a track to the Animation.
- String animation_track_get_key_animation ( int track_idx, int key_idx ) const
key_idx. Thetrack_idxmust be the index of an Animation Track.
- int animation_track_insert_key ( int track_idx, float time, String animation )
animationat the giventime(in seconds). Thetrack_idxmust be the index of an Animation Track.
- animation_track_set_key_animation ( int track_idx, int key_idx, String animation )
key_idxto valueanimation. Thetrack_idxmust be the index of an Animation Track.
- float audio_track_get_key_end_offset ( int track_idx, int key_idx ) const
key_idx. Thetrack_idxmust be the index of an Audio Track. End offset is the number of seconds cut off at the ending of the audio stream.
- float audio_track_get_key_start_offset ( int track_idx, int key_idx ) const
key_idx. Thetrack_idxmust be the index of an Audio Track. Start offset is the number of seconds cut off at the beginning of the audio stream.
- Resource audio_track_get_key_stream ( int track_idx, int key_idx ) const
key_idx. Thetrack_idxmust be the index of an Audio Track.
- int audio_track_insert_key ( int track_idx, float time, Resource stream, float start_offset=0, float end_offset=0 )
timein seconds. Thetrack_idxmust be the index of an Audio Track.streamis the AudioStream resource to play.start_offsetis the number of seconds cut off at the beginning of the audio stream, whileend_offsetis at the ending.
- audio_track_set_key_end_offset ( int track_idx, int key_idx, float offset )
key_idxto valueoffset. Thetrack_idxmust be the index of an Audio Track.
- audio_track_set_key_start_offset ( int track_idx, int key_idx, float offset )
key_idxto valueoffset. Thetrack_idxmust be the index of an Audio Track.
- audio_track_set_key_stream ( int track_idx, int key_idx, Resource stream )
key_idxto valuestream. Thetrack_idxmust be the index of an Audio Track.
- Vector2 bezier_track_get_key_in_handle ( int track_idx, int key_idx ) const
key_idx. Thetrack_idxmust be the index of a Bezier Track.
- Vector2 bezier_track_get_key_out_handle ( int track_idx, int key_idx ) const
key_idx. Thetrack_idxmust be the index of a Bezier Track.
- float bezier_track_get_key_value ( int track_idx, int key_idx ) const
key_idx. Thetrack_idxmust be the index of a Bezier Track.
- int bezier_track_insert_key ( int track_idx, float time, float value, Vector2 in_handle=Vector2( 0, 0 ), Vector2 out_handle=Vector2( 0, 0 ) )
timein seconds. Thetrack_idxmust be the index of a Bezier Track.in_handleis the left-side weight of the added Bezier curve point,out_handleis the right-side one, whilevalueis the actual value at this point.
- float bezier_track_interpolate ( int track_idx, float time ) const
time(in seconds). Thetrack_idxmust be the index of a Bezier Track.
- bezier_track_set_key_in_handle ( int track_idx, int key_idx, Vector2 in_handle )
key_idxto valuein_handle. Thetrack_idxmust be the index of a Bezier Track.
- bezier_track_set_key_out_handle ( int track_idx, int key_idx, Vector2 out_handle )
key_idxto valueout_handle. Thetrack_idxmust be the index of a Bezier Track.
- bezier_track_set_key_value ( int track_idx, int key_idx, float value )
key_idxto the given value. Thetrack_idxmust be the index of a Bezier Track.
- clear ( ) Clear the animation (clear all tracks and reset all).
- copy_track ( int track_idx, Animation to_animation )
to_animation.
- int find_track ( NodePath path ) const Returns the index of the specified track. If the track is not found, return -1.
- int get_track_count ( ) const Returns the amount of tracks in the animation.
- PoolIntArray method_track_get_key_indices ( int track_idx, float time_sec, float delta ) const Returns all the key indices of a method track, given a position and delta time.
- String method_track_get_name ( int track_idx, int key_idx ) const Returns the method name of a method track.
- Array method_track_get_params ( int track_idx, int key_idx ) const Returns the arguments values to be called on a method track for a given key in a given track.
- remove_track ( int track_idx ) Removes a track by specifying the track index.
- int track_find_key ( int track_idx, float time, bool exact=false ) const Finds the key index by time in a given track. Optionally, only find it if the exact time is given.
- bool track_get_interpolation_loop_wrap ( int track_idx ) const
trueif the track atidxwraps the interpolation loop. New tracks wrap the interpolation loop by default.
- InterpolationType track_get_interpolation_type ( int track_idx ) const Returns the interpolation type of a given track.
- int track_get_key_count ( int track_idx ) const Returns the amount of keys in a given track.
- float track_get_key_time ( int track_idx, int key_idx ) const Returns the time at which the key is located.
- float track_get_key_transition ( int track_idx, int key_idx ) const @GDScript.ease).
- Variant track_get_key_value ( int track_idx, int key_idx ) const Returns the value of a given key in a given track.
- NodePath track_get_path ( int track_idx ) const track_set_path.
- TrackType track_get_type ( int track_idx ) const Gets the type of a track.
- track_insert_key ( int track_idx, float time, Variant key, float transition=1 ) Insert a generic key in a given track.
- bool track_is_enabled ( int track_idx ) const
trueif the track at indexidxis enabled.
- bool track_is_imported ( int track_idx ) const
trueif the given track is imported. Else, returnfalse.
- track_move_down ( int track_idx ) Moves a track down.
- track_move_to ( int track_idx, int to_idx )
idxto the one defined into_idx.
- track_move_up ( int track_idx ) Moves a track up.
- track_remove_key ( int track_idx, int key_idx ) Removes a key by index in a given track.
- track_remove_key_at_position ( int track_idx, float position ) Removes a key by position (seconds) in a given track.
- track_set_enabled ( int track_idx, bool enabled ) Enables/disables the given track. Tracks are enabled by default.
- track_set_imported ( int track_idx, bool imported ) Sets the given track as imported or not.
- track_set_interpolation_loop_wrap ( int track_idx, bool interpolation )
true, the track atidxwraps the interpolation loop.
- track_set_interpolation_type ( int track_idx, InterpolationType interpolation ) Sets the interpolation type of a given track.
- track_set_key_time ( int track_idx, int key_idx, float time ) Sets the time of an existing key.
- track_set_key_transition ( int track_idx, int key_idx, float transition ) @GDScript.ease).
- track_set_key_value ( int track_idx, int key, Variant value ) Sets the value of an existing key.
- track_set_path ( int track_idx, NodePath path )
":"."character/skeleton:ankle"or"character/mesh:transform/local".
- track_swap ( int track_idx, int with_idx )
idx‘s index position with the trackwith_idx.
- int transform_track_insert_key ( int track_idx, float time, Vector3 location, Quat rotation, Vector3 scale ) Insert a transform key for a transform track.
- Array transform_track_interpolate ( int track_idx, float time_sec ) const Vector3), rotation (Quat) and scale (Vector3).
- PoolIntArray value_track_get_key_indices ( int track_idx, float time_sec, float delta ) const Returns all the key indices of a value track, given a position and delta time.
- UpdateMode value_track_get_update_mode ( int track_idx ) const Returns the update mode of a value track.
- Variant value_track_interpolate ( int track_idx, float time_sec ) const
track_idxmust be the index of a value track.
- value_track_set_update_mode ( int track_idx, UpdateMode mode ) UpdateMode) of a value track.
