AnimationPlayer
Inherits: Node < Object Animation resources.
Description
Animation resources. It contains a dictionary of animations (referenced by name) and custom blend times between their transitions. Additionally, animations can be played and blended in different channels.
AnimationPlayer is more suited than Tween for animations where you know the final values in advance. For example, fading a screen in and out is more easily done with an AnimationPlayer node thanks to the animation tools provided by the editor. That particular example can also be implemented with a Tween node, but it requires doing everything by code.
Updating the target properties of animations occurs at process time.
Tutorials
- Animation tutorial index
- 2D Sprite animation
- Third Person Shooter Demo
Properties
Methods
Signals
- animation_changed ( String old_name, String new_name ) queue. Note: The signal is not emitted when the animation is changed via play or from AnimationTree.
- animation_finished ( String anim_name ) Notifies when an animation finished playing.
- animation_started ( String anim_name ) Notifies when an animation starts playing.
- caches_cleared ( )
clear_caches.
Enumerations
AnimationProcessMode: - ANIMATION_PROCESS_PHYSICS = 0 —- Process animation during the physics process. This is especially useful when animating physics bodies.
- ANIMATION_PROCESS_IDLE = 1 —- Process animation during the idle process.
- ANIMATION_PROCESS_MANUAL = 2 —- Do not process animation. Use advance to process the animation manually.
AnimationMethodCallMode:
- ANIMATION_METHOD_CALL_DEFERRED = 0 —- Batch method calls during the animation process, then do the calls after events are processed. This avoids bugs involving deleting nodes or modifying the AnimationPlayer while playing.
- ANIMATION_METHOD_CALL_IMMEDIATE = 1 —- Make method calls immediately when reached in the animation.
Property Descriptions
- String assigned_animation current_animation.
- String autoplay The name of the animation to play when the scene loads.
- String current_animation play for more information on playing animations. Note: 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.
- float current_animation_length The length (in seconds) of the currently being played animation.
- float current_animation_position The position (in seconds) of the currently playing animation.
- AnimationMethodCallMode method_call_mode The call mode to use for Call Method tracks.
- bool playback_active
true, updates animations in response to process-related notifications.
- float playback_default_blend_time The default time in which to blend animations. Ranges from 0 to 4096 with 0.01 precision.
- AnimationProcessMode playback_process_mode The process notification in which to update animations.
- float playback_speed The speed scaling ratio. For instance, if this value is 1, then the animation plays at normal speed. If it’s 0.5, then it plays at half speed. If it’s 2, then it plays at double speed.
- bool reset_on_save
true, the scene will be saved with the effects of the reset animation applied (as if it had been seeked to time 0), then reverted after saving. In other words, the saved scene file will contain the “default pose”, as defined by the reset animation, if any, with the editor keeping the values that the nodes had before saving.
- NodePath root_node
The node from which node path references will travel.
Method Descriptions
- Error add_animation ( String name, Animation animation )
animationto the player accessible with the keyname.
- advance ( float delta )
deltais the time in seconds to shift. Events between the current frame anddeltaare handled.
- String animation_get_next ( String anim_from ) const Returns the name of the next animation in the queue.
- animation_set_next ( String anim_from, String anim_to )
anim_toanimation when theanim_fromanimation completes.
- clear_caches ( )
AnimationPlayercaches animated nodes. It may not notice if a node disappears; clear_caches forces it to update the cache again.
- clear_queue ( ) Clears all queued, unplayed animations.
- String find_animation ( Animation animation ) const
animationor an empty string if not found.
- Animation get_animation ( String name ) const
Animation with key
nameornullif not found.
- PoolStringArray get_animation_list ( ) const Returns the list of stored animation names.
- float get_blend_time ( String anim_from, String anim_to ) const Gets the blend time (in seconds) between two animations, referenced by their names.
- float get_playing_speed ( ) const
playback_speed property multiplied by
custom_speedargument specified when calling the play method.
- PoolStringArray get_queue ( ) Returns a list of the animation names that are currently queued to play.
- bool has_animation ( String name ) const
trueif theAnimationPlayerstores an Animation with keyname.
- bool is_playing ( ) const
trueif playing an animation.
- play ( String name=””, float custom_blend=-1, float custom_speed=1.0, bool from_end=false )
name. Custom blend times and speed can be set. Ifcustom_speedis negative andfrom_endistrue, the animation will play backwards (which is equivalent to calling play_backwards).AnimationPlayerkeeps track of its current or last played animation with assigned_animation. If this method is called with that same animationname, or with nonameparameter, the assigned animation will resume playing if it was paused, or restart if it was stopped (see stop for both pause and stop). If the animation was already playing, it will keep playing. Note: The animation will be updated the next time theAnimationPlayeris processed. If other variables are updated at the same time this is called, they may be updated too early. To perform the update immediately, calladvance(0).
- play_backwards ( String name=””, float custom_blend=-1 )
namein reverse. play withcustom_speed = -1.0andfrom_end = true, so see its description for more information.
- queue ( String name ) Queues an animation for playback once the current one is done. Note: If a looped animation is currently playing, the queued animation will never play unless the looped animation is stopped somehow.
- remove_animation ( String name )
name.
- rename_animation ( String name, String newname )
nametonewname.
- seek ( float seconds, bool update=false )
secondspoint in time (in seconds). Ifupdateistrue, the animation updates too, otherwise it updates at process time. Events between the current frame andsecondsare skipped. Note: Seeking to the end of the animation doesn’t emit animation_finished. If you want to skip animation and emit the signal, use advance.
- set_blend_time ( String anim_from, String anim_to, float sec ) Specifies a blend time (in seconds) between two animations, referenced by their names.
- stop ( bool reset=true )
resetistrue, the animation position is reset to0and the playback speed is reset to1.0.resetisfalse, the current_animation_position will be kept and calling play or play_backwards without arguments or with the same animation name as assigned_animation will resume the animation.
