AnimationPlayer
A node used for animation playback.
AnimationPlayer.swift:24class AnimationPlayer
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.
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 "movement/run"
. 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.
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.
Updating the target properties of animations occurs at the process frame.
This object emits the following signals:
Superclasses
class AnimationMixer
Base class for
AnimationPlayer
andAnimationTree
.
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
enum AnimationMethodCallMode
enum AnimationProcessCallback
class Signal1
Signal support.
class Signal2
Signal support.
Type members
Instance members
var animationChanged: Signal2
Emitted when a queued animation plays after the previous animation finished. See also
queue(name:)
.var assignedAnimation: String
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
currentAnimation
.var autoplay: String
The key of the animation to play when the scene loads.
var currentAnimation: String
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
play(name:customBlend:customSpeed:fromEnd:)
for more information on playing animations.var currentAnimationChanged: Signal1
Emitted when
currentAnimation
changes.var currentAnimationLength: Double
The length (in seconds) of the currently playing animation.
var currentAnimationPosition: Double
The position (in seconds) of the currently playing animation.
var movieQuitOnFinish: Bool
If
true
and the engine is running in Movie Maker mode (seeMovieWriter
), exits the engine withquit(exitCode:)
as soon as an animation is done playing in thisAnimationPlayer
. A message is printed when the engine quits for this reason.var playbackDefaultBlendTime: Double
The default time in which to blend animations. Ranges from 0 to 4096 with 0.01 precision.
var speedScale: Double
The speed scaling ratio. For example, if this value is
1
, then the animation plays at normal speed. If it’s0.5
, then it plays at half speed. If it’s2
, then it plays at double speed.func animationGetNext(animationFrom: StringName
) -> StringName Returns the key of the animation which is queued to play after the
animationFrom
animation.func animationSetNext(animationFrom: StringName, animationTo: StringName
) Triggers the
animationTo
animation when theanimationFrom
animation completes.func clearQueue(
) Clears all queued, unplayed animations.
func getBlendTime(animationFrom: StringName, animationTo: StringName
) -> Double Returns the blend time (in seconds) between two animations, referenced by their keys.
func getMethodCallMode(
) -> AnimationPlayer.AnimationMethodCallMode For backward compatibility. See
AnimationMixer.AnimationCallbackModeMethod
.func getPlayingSpeed(
) -> Double Returns the actual playing speed of current animation or
0
if not playing. This speed is thespeedScale
property multiplied bycustom_speed
argument specified when calling theplay(name:customBlend:customSpeed:fromEnd:)
method.func getProcessCallback(
) -> AnimationPlayer.AnimationProcessCallback For backward compatibility. See
AnimationMixer.AnimationCallbackModeProcess
.func getQueue(
) -> PackedStringArray Returns a list of the animation keys that are currently queued to play.
func getRoot(
) -> NodePath For backward compatibility. See
rootNode
.func isPlaying(
) -> Bool Returns
true
if an animation is currently playing (even ifspeedScale
and/orcustom_speed
are0
).func pause(
) Pauses the currently playing animation. The
currentAnimationPosition
will be kept and callingplay(name:customBlend:customSpeed:fromEnd:)
orplayBackwards(name:customBlend:)
without arguments or with the same animation name asassignedAnimation
will resume the animation.func play(name: StringName, customBlend: Double, customSpeed: Double, fromEnd: Bool
) Plays the animation with key
name
. Custom blend times and speed can be set.func playBackwards(name: StringName, customBlend: Double
) Plays the animation with key
name
in reverse.func queue(name: StringName
) Queues an animation for playback once the current one is done.
func seek(seconds: Double, update: Bool, updateOnly: Bool
) Seeks the animation to the
seconds
point in time (in seconds). Ifupdate
istrue
, the animation updates too, otherwise it updates at process time. Events between the current frame andseconds
are skipped.func setBlendTime(animationFrom: StringName, animationTo: StringName, sec: Double
) Specifies a blend time (in seconds) between two animations, referenced by their keys.
func setMethodCallMode(AnimationPlayer.AnimationMethodCallMode
) For backward compatibility. See
AnimationMixer.AnimationCallbackModeMethod
.func setProcessCallback(mode: AnimationPlayer.AnimationProcessCallback
) For backward compatibility. See
AnimationMixer.AnimationCallbackModeProcess
.func setRoot(path: NodePath
) For backward compatibility. See
rootNode
.func stop(keepState: Bool
) Stops the currently playing animation. The animation position is reset to
0
and thecustom_speed
is reset to1.0
. See alsopause
.