Animation
Holds data that can be used to animate anything in the engine.
Animation.swift:16class Animation
This resource holds data that can be used to animate anything 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.
Animations are just data containers, and must be added to nodes such as an AnimationPlayer
to be played back. Animation tracks have different types, each with its own set of dedicated methods. Check TrackType
to see available types.
Superclasses
class Resource
Base class for serializable objects.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
Type members
Instance members
var length: Double
The total length of the animation (in seconds).
var loopMode: Animation.LoopMode
Determines the behavior of both ends of the animation timeline during animation playback. This is used for correct interpolation of animation cycles, and for hinting the player that it must restart the animation.
var step: Double
The animation step value.
func addTrack(type: Animation.TrackType, atPosition: Int32
) -> Int32 Adds a track to the Animation.
func animationTrackGetKeyAnimation(trackIdx: Int32, keyIdx: Int32
) -> StringName Returns the animation name at the key identified by
keyIdx
. ThetrackIdx
must be the index of an Animation Track.func animationTrackInsertKey(trackIdx: Int32, time: Double, animation: StringName
) -> Int32 Inserts a key with value
animation
at the giventime
(in seconds). ThetrackIdx
must be the index of an Animation Track.func animationTrackSetKeyAnimation(trackIdx: Int32, keyIdx: Int32, animation: StringName
) Sets the key identified by
keyIdx
to valueanimation
. ThetrackIdx
must be the index of an Animation Track.func audioTrackGetKeyEndOffset(trackIdx: Int32, keyIdx: Int32
) -> Double Returns the end offset of the key identified by
keyIdx
. ThetrackIdx
must be the index of an Audio Track.func audioTrackGetKeyStartOffset(trackIdx: Int32, keyIdx: Int32
) -> Double Returns the start offset of the key identified by
keyIdx
. ThetrackIdx
must be the index of an Audio Track.func audioTrackGetKeyStream(trackIdx: Int32, keyIdx: Int32
) -> Resource? Returns the audio stream of the key identified by
keyIdx
. ThetrackIdx
must be the index of an Audio Track.func audioTrackInsertKey(trackIdx: Int32, time: Double, stream: Resource?, startOffset: Double, endOffset: Double
) -> Int32 Inserts an Audio Track key at the given
time
in seconds. ThetrackIdx
must be the index of an Audio Track.func audioTrackIsUseBlend(trackIdx: Int32
) -> Bool Returns
true
if the track attrackIdx
will be blended with other animations.func audioTrackSetKeyEndOffset(trackIdx: Int32, keyIdx: Int32, offset: Double
) Sets the end offset of the key identified by
keyIdx
to valueoffset
. ThetrackIdx
must be the index of an Audio Track.func audioTrackSetKeyStartOffset(trackIdx: Int32, keyIdx: Int32, offset: Double
) Sets the start offset of the key identified by
keyIdx
to valueoffset
. ThetrackIdx
must be the index of an Audio Track.func audioTrackSetKeyStream(trackIdx: Int32, keyIdx: Int32, stream: Resource?
) Sets the stream of the key identified by
keyIdx
to valuestream
. ThetrackIdx
must be the index of an Audio Track.func audioTrackSetUseBlend(trackIdx: Int32, enable: Bool
) Sets whether the track will be blended with other animations. If
true
, the audio playback volume changes depending on the blend value.func bezierTrackGetKeyInHandle(trackIdx: Int32, keyIdx: Int32
) -> Vector2 Returns the in handle of the key identified by
keyIdx
. ThetrackIdx
must be the index of a Bezier Track.func bezierTrackGetKeyOutHandle(trackIdx: Int32, keyIdx: Int32
) -> Vector2 Returns the out handle of the key identified by
keyIdx
. ThetrackIdx
must be the index of a Bezier Track.func bezierTrackGetKeyValue(trackIdx: Int32, keyIdx: Int32
) -> Double Returns the value of the key identified by
keyIdx
. ThetrackIdx
must be the index of a Bezier Track.func bezierTrackInsertKey(trackIdx: Int32, time: Double, value: Double, inHandle: Vector2, outHandle: Vector2
) -> Int32 Inserts a Bezier Track key at the given
time
in seconds. ThetrackIdx
must be the index of a Bezier Track.func bezierTrackInterpolate(trackIdx: Int32, time: Double
) -> Double Returns the interpolated value at the given
time
(in seconds). ThetrackIdx
must be the index of a Bezier Track.func bezierTrackSetKeyInHandle(trackIdx: Int32, keyIdx: Int32, inHandle: Vector2, balancedValueTimeRatio: Double
) Sets the in handle of the key identified by
keyIdx
to valueinHandle
. ThetrackIdx
must be the index of a Bezier Track.func bezierTrackSetKeyOutHandle(trackIdx: Int32, keyIdx: Int32, outHandle: Vector2, balancedValueTimeRatio: Double
) Sets the out handle of the key identified by
keyIdx
to valueoutHandle
. ThetrackIdx
must be the index of a Bezier Track.func bezierTrackSetKeyValue(trackIdx: Int32, keyIdx: Int32, value: Double
) Sets the value of the key identified by
keyIdx
to the given value. ThetrackIdx
must be the index of a Bezier Track.func blendShapeTrackInsertKey(trackIdx: Int32, time: Double, amount: Double
) -> Int32 Inserts a key in a given blend shape track. Returns the key index.
func blendShapeTrackInterpolate(trackIdx: Int32, timeSec: Double
) -> Double Returns the interpolated blend shape value at the given time (in seconds). The
trackIdx
must be the index of a blend shape track.func clear(
) Clear the animation (clear all tracks and reset all).
func compress(pageSize: UInt32, fps: UInt32, splitTolerance: Double
) Compress the animation and all its tracks in-place. This will make
trackIsCompressed(trackIdx:)
returntrue
once called on thisAnimation
. Compressed tracks require less memory to be played, and are designed to be used for complex 3D animations (such as cutscenes) imported from external 3D software. Compression is lossy, but the difference is usually not noticeable in real world conditions.func copyTrack(trackIdx: Int32, toAnimation: Animation?
) Adds a new track to
toAnimation
that is a copy of the given track from this animation.func findTrack(path: NodePath, type: Animation.TrackType
) -> Int32 Returns the index of the specified track. If the track is not found, return -1.
func getTrackCount(
) -> Int32 Returns the amount of tracks in the animation.
func methodTrackGetName(trackIdx: Int32, keyIdx: Int32
) -> StringName Returns the method name of a method track.
func methodTrackGetParams(trackIdx: Int32, keyIdx: Int32
) -> GArray Returns the arguments values to be called on a method track for a given key in a given track.
func positionTrackInsertKey(trackIdx: Int32, time: Double, position: Vector3
) -> Int32 Inserts a key in a given 3D position track. Returns the key index.
func positionTrackInterpolate(trackIdx: Int32, timeSec: Double
) -> Vector3 Returns the interpolated position value at the given time (in seconds). The
trackIdx
must be the index of a 3D position track.func removeTrack(trackIdx: Int32
) Removes a track by specifying the track index.
func rotationTrackInsertKey(trackIdx: Int32, time: Double, rotation: Quaternion
) -> Int32 Inserts a key in a given 3D rotation track. Returns the key index.
func rotationTrackInterpolate(trackIdx: Int32, timeSec: Double
) -> Quaternion Returns the interpolated rotation value at the given time (in seconds). The
trackIdx
must be the index of a 3D rotation track.func scaleTrackInsertKey(trackIdx: Int32, time: Double, scale: Vector3
) -> Int32 Inserts a key in a given 3D scale track. Returns the key index.
func scaleTrackInterpolate(trackIdx: Int32, timeSec: Double
) -> Vector3 Returns the interpolated scale value at the given time (in seconds). The
trackIdx
must be the index of a 3D scale track.func trackFindKey(trackIdx: Int32, time: Double, findMode: Animation.FindMode
) -> Int32 Finds the key index by time in a given track. Optionally, only find it if the approx/exact time is given.
func trackGetInterpolationLoopWrap(trackIdx: Int32
) -> Bool Returns
true
if the track attrackIdx
wraps the interpolation loop. New tracks wrap the interpolation loop by default.func trackGetInterpolationType(trackIdx: Int32
) -> Animation.InterpolationType Returns the interpolation type of a given track.
func trackGetKeyCount(trackIdx: Int32
) -> Int32 Returns the number of keys in a given track.
func trackGetKeyTime(trackIdx: Int32, keyIdx: Int32
) -> Double Returns the time at which the key is located.
func trackGetKeyTransition(trackIdx: Int32, keyIdx: Int32
) -> Double Returns the transition curve (easing) for a specific key (see the built-in math function
@GlobalScope.ease
).func trackGetKeyValue(trackIdx: Int32, keyIdx: Int32
) -> Variant Returns the value of a given key in a given track.
func trackGetPath(trackIdx: Int32
) -> NodePath Gets the path of a track. For more information on the path format, see
trackSetPath(trackIdx:path:)
.func trackGetType(trackIdx: Int32
) -> Animation.TrackType Gets the type of a track.
func trackInsertKey(trackIdx: Int32, time: Double, key: Variant, transition: Double
) -> Int32 Inserts a generic key in a given track. Returns the key index.
func trackIsCompressed(trackIdx: Int32
) -> Bool Returns
true
if the track is compressed,false
otherwise. See alsocompress(pageSize:fps:splitTolerance:)
.func trackIsEnabled(trackIdx: Int32
) -> Bool Returns
true
if the track at indextrackIdx
is enabled.func trackIsImported(trackIdx: Int32
) -> Bool Returns
true
if the given track is imported. Else, returnfalse
.func trackMoveDown(trackIdx: Int32
) Moves a track down.
func trackMoveTo(trackIdx: Int32, toIdx: Int32
) Changes the index position of track
trackIdx
to the one defined intoIdx
.func trackMoveUp(trackIdx: Int32
) Moves a track up.
func trackRemoveKey(trackIdx: Int32, keyIdx: Int32
) Removes a key by index in a given track.
func trackRemoveKeyAtTime(trackIdx: Int32, time: Double
) Removes a key at
time
in a given track.func trackSetEnabled(trackIdx: Int32, enabled: Bool
) Enables/disables the given track. Tracks are enabled by default.
func trackSetImported(trackIdx: Int32, imported: Bool
) Sets the given track as imported or not.
func trackSetInterpolationLoopWrap(trackIdx: Int32, interpolation: Bool
) If
true
, the track attrackIdx
wraps the interpolation loop.func trackSetInterpolationType(trackIdx: Int32, interpolation: Animation.InterpolationType
) Sets the interpolation type of a given track.
func trackSetKeyTime(trackIdx: Int32, keyIdx: Int32, time: Double
) Sets the time of an existing key.
func trackSetKeyTransition(trackIdx: Int32, keyIdx: Int32, transition: Double
) Sets the transition curve (easing) for a specific key (see the built-in math function
@GlobalScope.ease
).func trackSetKeyValue(trackIdx: Int32, key: Int32, value: Variant
) Sets the value of an existing key.
func trackSetPath(trackIdx: Int32, path: NodePath
) 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
":"
.func trackSwap(trackIdx: Int32, withIdx: Int32
) Swaps the track
trackIdx
’s index position with the trackwithIdx
.func valueTrackGetUpdateMode(trackIdx: Int32
) -> Animation.UpdateMode Returns the update mode of a value track.
func valueTrackInterpolate(trackIdx: Int32, timeSec: Double
) -> Variant Returns the interpolated value at the given time (in seconds). The
trackIdx
must be the index of a value track.func valueTrackSetUpdateMode(trackIdx: Int32, mode: Animation.UpdateMode
) Sets the update mode (see
UpdateMode
) of a value track.