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)
Animations are just data containers, and must be added to nodes such as an godot.AnimationPlayer
or godot.AnimationTreePlayer
to be played back. Animation tracks have different types, each with its own set of dedicated methods. Check godot.Animation_TrackType
to see available types.
Constructor
Variables
length:Single
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.
loop:Bool
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.
Methods
animationTrackGetKeyAnimation(trackIdx:Int, keyIdx:Int):String
Returns the animation name at the key identified by key_idx
. The track_idx
must be the index of an Animation Track.
animationTrackInsertKey(trackIdx:Int, time:Single, animation:String):Int
Inserts a key with value animation
at the given time
(in seconds). The track_idx
must be the index of an Animation Track.
animationTrackSetKeyAnimation(trackIdx:Int, keyIdx:Int, animation:String):Void
Sets the key identified by key_idx
to value animation
. The track_idx
must be the index of an Animation Track.
audioTrackGetKeyEndOffset(trackIdx:Int, keyIdx:Int):Single
Returns the end offset of the key identified by key_idx
. The track_idx
must be the index of an Audio Track.
End offset is the number of seconds cut off at the ending of the audio stream.
audioTrackGetKeyStartOffset(trackIdx:Int, keyIdx:Int):Single
Returns the start offset of the key identified by key_idx
. The track_idx
must be the index of an Audio Track.
Start offset is the number of seconds cut off at the beginning of the audio stream.
audioTrackGetKeyStream(trackIdx:Int, keyIdx:Int):Resource
Returns the audio stream of the key identified by key_idx
. The track_idx
must be the index of an Audio Track.
audioTrackInsertKey(trackIdx:Int, time:Single, stream:Resource, ?startOffset:Single, ?endOffset:Single):Int
Inserts an Audio Track key at the given time
in seconds. The track_idx
must be the index of an Audio Track.
stream
is the godot.AudioStream
resource to play. start_offset
is the number of seconds cut off at the beginning of the audio stream, while end_offset
is at the ending.
audioTrackSetKeyEndOffset(trackIdx:Int, keyIdx:Int, offset:Single):Void
Sets the end offset of the key identified by key_idx
to value offset
. The track_idx
must be the index of an Audio Track.
audioTrackSetKeyStartOffset(trackIdx:Int, keyIdx:Int, offset:Single):Void
Sets the start offset of the key identified by key_idx
to value offset
. The track_idx
must be the index of an Audio Track.
audioTrackSetKeyStream(trackIdx:Int, keyIdx:Int, stream:Resource):Void
Sets the stream of the key identified by key_idx
to value stream
. The track_idx
must be the index of an Audio Track.
bezierTrackGetKeyInHandle(trackIdx:Int, keyIdx:Int):Vector2
Returns the in handle of the key identified by key_idx
. The track_idx
must be the index of a Bezier Track.
bezierTrackGetKeyOutHandle(trackIdx:Int, keyIdx:Int):Vector2
Returns the out handle of the key identified by key_idx
. The track_idx
must be the index of a Bezier Track.
bezierTrackGetKeyValue(trackIdx:Int, keyIdx:Int):Single
Returns the value of the key identified by key_idx
. The track_idx
must be the index of a Bezier Track.
bezierTrackInsertKey(trackIdx:Int, time:Single, value:Single, ?inHandle:Vector2, ?outHandle:Vector2):Int
Inserts a Bezier Track key at the given time
in seconds. The track_idx
must be the index of a Bezier Track.
in_handle
is the left-side weight of the added Bezier curve point, out_handle
is the right-side one, while value
is the actual value at this point.
Parameters:
inHandle | If the parameter is null, then the default value is new Vector2(0, 0) |
---|---|
outHandle | If the parameter is null, then the default value is new Vector2(0, 0) |
bezierTrackInterpolate(trackIdx:Int, time:Single):Single
Returns the interpolated value at the given time
(in seconds). The track_idx
must be the index of a Bezier Track.
bezierTrackSetKeyInHandle(trackIdx:Int, keyIdx:Int, inHandle:Vector2):Void
Sets the in handle of the key identified by key_idx
to value in_handle
. The track_idx
must be the index of a Bezier Track.
bezierTrackSetKeyOutHandle(trackIdx:Int, keyIdx:Int, outHandle:Vector2):Void
Sets the out handle of the key identified by key_idx
to value out_handle
. The track_idx
must be the index of a Bezier Track.
bezierTrackSetKeyValue(trackIdx:Int, keyIdx:Int, value:Single):Void
Sets the value of the key identified by key_idx
to the given value. The track_idx
must be the index of a Bezier Track.
copyTrack(trackIdx:Int, toAnimation:Animation):Void
Adds a new track that is a copy of the given track from to_animation
.
findTrack(path:NodePath):Int
Returns the index of the specified track. If the track is not found, return -1.
inlinemethodTrackGetKeyIndices(trackIdx:Int, timeSec:Single, delta:Single):Array<Int>
Returns all the key indices of a method track, given a position and delta time.
methodTrackGetParams(trackIdx:Int, keyIdx:Int):Array
Returns the arguments values to be called on a method track for a given key in a given track.
trackFindKey(trackIdx:Int, time:Single, ?exact:Bool):Int
Finds the key index by time in a given track. Optionally, only find it if the exact time is given.
trackGetInterpolationLoopWrap(trackIdx:Int):Bool
Returns true
if the track at idx
wraps the interpolation loop. New tracks wrap the interpolation loop by default.
trackGetInterpolationType(trackIdx:Int):Animation_InterpolationType
Returns the interpolation type of a given track.
trackGetKeyTransition(trackIdx:Int, keyIdx:Int):Single
Returns the transition curve (easing) for a specific key (see the built-in math function @GDScript.ease
).
trackGetKeyValue(trackIdx:Int, keyIdx:Int):Dynamic
Returns the value of a given key in a given track.
trackGetPath(trackIdx:Int):NodePath
Gets the path of a track. For more information on the path format, see godot.Animation.trackSetPath
.
trackInsertKey(trackIdx:Int, time:Single, key:Dynamic, ?transition:Single):Void
Insert a generic key in a given track.
trackMoveTo(trackIdx:Int, toIdx:Int):Void
Changes the index position of track idx
to the one defined in to_idx
.
trackRemoveKeyAtPosition(trackIdx:Int, position:Single):Void
Removes a key by position (seconds) in a given track.
trackSetEnabled(trackIdx:Int, enabled:Bool):Void
Enables/disables the given track. Tracks are enabled by default.
trackSetInterpolationLoopWrap(trackIdx:Int, interpolation:Bool):Void
If true
, the track at idx
wraps the interpolation loop.
trackSetInterpolationType(trackIdx:Int, interpolation:Animation_InterpolationType):Void
Sets the interpolation type of a given track.
trackSetKeyTransition(trackIdx:Int, keyIdx:Int, transition:Single):Void
Sets the transition curve (easing) for a specific key (see the built-in math function @GDScript.ease
).
trackSetPath(trackIdx:Int, path:NodePath):Void
Sets the path of a track. Paths must be valid scene-tree paths to a node and must be specified starting from the parent node of the node that will reproduce the animation. Tracks that control properties or bones must append their name after the path, separated by ":"
.
For example, "character/skeleton:ankle"
or "character/mesh:transform/local"
.
trackSwap(trackIdx:Int, withIdx:Int):Void
Swaps the track idx
's index position with the track with_idx
.
transformTrackInsertKey(trackIdx:Int, time:Single, location:Vector3, rotation:Quat, scale:Vector3):Int
Insert a transform key for a transform track.
transformTrackInterpolate(trackIdx:Int, timeSec:Single):Array
Returns the interpolated value of a transform track at a given time (in seconds). An array consisting of 3 elements: position (godot.Vector3
), rotation (godot.Quat
) and scale (godot.Vector3
).
inlinevalueTrackGetKeyIndices(trackIdx:Int, timeSec:Single, delta:Single):Array<Int>
Returns all the key indices of a value track, given a position and delta time.
valueTrackInterpolate(trackIdx:Int, timeSec:Single):Dynamic
Returns the interpolated value at the given time (in seconds). The track_idx
must be the index of a value track.
valueTrackSetUpdateMode(trackIdx:Int, mode:Animation_UpdateMode):Void
Sets the update mode (see godot.Animation_UpdateMode
) of a value track.