Animation

Play a sequence of images or a GIF as an animated Sprite.

Animation

Animation(name, fps=12, loop=True, autoplay=True, frame_times=None, **kwargs)

Located in ursina/prefabs/animation.py

Overview

Animation loads a series of image files or a GIF and displays them as frames on a Sprite. You can control playback speed with fps, choose whether it repeats, and start or stop it at any time.

Constructor Arguments

ArgumentTypeDefaultDescription
namestrBase filename or path. If files are img_000.png, img_001.png, use "img"; support GIFs.
fpsint12Frames per second. Faster FPS shortens total duration.
loopboolTrueWhether to repeat when the sequence ends.
autoplayboolTrueIf True, start playing immediately after creation.
frame_timeslist[float]NoneCustom display time for each frame (in seconds). Overrides fps if provided.
**kwargsanyAny other Sprite parameters (position, scale, parent, etc.).

Properties

PropertyDescription
.durationTotal playtime in seconds. Computed from fps or frame_times. Cannot be set directly.
.is_playingbool, whether the animation is currently running.

Methods

MethodDescription
start()Begin playback from the first frame or resume if paused.
pause()Temporarily stop at the current frame.
resume()Continue playback from the paused frame.
finish()Advance to the last frame and stop.

Example

from ursina import *
from ursina.prefabs.animation import Animation

app = Ursina()

# load files named walk_000.png, walk_001.png, ...
walk = Animation('walk', fps=8, loop=True, autoplay=True, position=(0,1,0))

# pause after 2 seconds
invoke(walk.pause, delay=2)
# resume 1 second later
invoke(walk.resume, delay=3)

app.run()