AnimatedSprite2D
Sprite node that contains multiple textures as frames to play for animation.
AnimatedSprite2D.swift:26class AnimatedSprite2D
AnimatedSprite2D
is similar to the Sprite2D
node, except it carries multiple textures as animation frames. Animations are created using a SpriteFrames
resource, which allows you to import image files (or a folder containing said files) to provide the animation frames for the sprite. The SpriteFrames
resource can be configured in the editor via the SpriteFrames bottom panel.
This object emits the following signals:
Superclasses
class Node2D
A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and Z index.
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.
Type members
Instance members
var animation: StringName
The current animation from the
spriteFrames
resource. If this value is changed, theframe
counter and theframeProgress
are reset.var animationChanged: SimpleSignal
Emitted when
animation
changes.var animationFinished: SimpleSignal
Emitted when the animation reaches the end, or the start if it is played in reverse. When the animation finishes, it pauses the playback.
var animationLooped: SimpleSignal
Emitted when the animation loops.
var autoplay: String
The key of the animation to play when the scene loads.
var centered: Bool
If
true
, texture will be centered.var flipH: Bool
If
true
, texture is flipped horizontally.var flipV: Bool
If
true
, texture is flipped vertically.var frame: Int32
The displayed animation frame’s index. Setting this property also resets
frameProgress
. If this is not desired, usesetFrameAndProgress(frame:progress:)
.var frameChanged: SimpleSignal
Emitted when
frame
changes.var frameProgress: Double
The progress value between
0.0
and1.0
until the current frame transitions to the next frame. If the animation is playing backwards, the value transitions from1.0
to0.0
.var offset: Vector2
The texture’s drawing offset.
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.var spriteFrames: SpriteFrames?
The
SpriteFrames
resource containing the animation(s). Allows you the option to load, edit, clear, make unique and save the states of theSpriteFrames
resource.var spriteFramesChanged: SimpleSignal
Emitted when
spriteFrames
changes.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:customSpeed:fromEnd:)
method.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
frame
andframeProgress
will be kept and callingplay(name:customSpeed:fromEnd:)
orplayBackwards(name:)
without arguments will resume the animation from the current playback position.func play(name: StringName, customSpeed: Double, fromEnd: Bool
) Plays the animation with key
name
. IfcustomSpeed
is negative andfromEnd
istrue
, the animation will play backwards (which is equivalent to callingplayBackwards(name:)
).func playBackwards(name: StringName
) Plays the animation with key
name
in reverse.func setFrameAndProgress(frame: Int32, progress: Double
) The setter of
frame
resets theframeProgress
to0.0
implicitly, but this method avoids that.func stop(
) Stops the currently playing animation. The animation position is reset to
0
and thecustom_speed
is reset to1.0
. See alsopause
.