AnimationController

A sprite animation manager and controller.

Constructor

AnimationController()

Load animations with load_sprite_sheet before using.

Properties


NameDescriptionType
current_animation_nameThe current animation's namestr
clipThe source rectangle (clip) for the current animation frameRect
textureThe sprite sheet texture used by this animation controllerTexture
playback_speedThe playback speed multiplierfloat
frame_indexThe current frame index of the animationint
progressThe progress through the current animation as a value between 0.0 and 1.0float
loopingWhether the animation should loop after playingbool

Methods


Load Sprite Sheet

load_sprite_sheet(
    file_path: str,
    frame_size: Vec2,
    strips: list[SheetStrip]
) None

Load animation frames from a sprite sheet. Strips are read horizontally from left to right, top to bottom, as provided in the strips list.

Parameters

  • file_path : The path to the sprite sheet image file.
  • frame_size : The size of each frame in the sprite sheet.
  • strips : A list of sheet strips to load from the sprite sheet.

Set

set(name: str) None

Set the current animation by name without affecting playback state.

Parameters

  • name : The name of the animation to set as current.

Play

play(name: str) None

Play an animation from the beginning by name.

Parameters

  • name : The name of the animation to play.

Play From

play_from(frame_index: int) None

Play an animation from a specific frame.

Parameters

  • frame_index : The index of the frame to start playing from.

Is Finished

is_finished() bool

Check if the current animation has finished a loop since the last frame update.

Returns

bool : True if the animation is finished, otherwise False.

Rewind

rewind() None

Rewind the current animation to the first frame.

Pause

pause() None

Pause the current animation.

Resume

resume() None

Resume the current animation.