SpriteAnimation
January 7, 2026 ยท View on GitHub
GMR Docs > Engine > Animation > SpriteAnimation
SpriteAnimation
Frame-based sprite animations.
Table of Contents
Instance Methods
#initialize
Create a new sprite animation.
Parameters:
| Name | Type | Description |
|---|---|---|
sprite | Sprite | The sprite to animate |
Example:
# Attack combo with non-looping animation
#play
Start or resume the animation.
Returns: SpriteAnimation - self for chaining
Example:
# State machine integration - play animation when entering run state
state :run do
enter { @animations[:run].play }
exit { @animations[:run].stop }
on :stop, :idle
on :jump, :jumping
end
#pause
Pause the animation at the current frame.
Returns: SpriteAnimation - self for chaining
Example:
anim.pause
#stop
Stop the animation and reset to the first frame.
Returns: SpriteAnimation - self for chaining
Example:
anim.stop
#on_complete
Set a callback for when the animation finishes (non-looping only).
Returns: SpriteAnimation - self for chaining
Example:
# Chain attack animation into recovery state
def start_attack
#on_frame_change
Set a callback for each frame change. Receives frame index.
Returns: SpriteAnimation - self for chaining
Example:
# Spawn attack hitbox on specific frame
#playing?
Check if the animation is currently playing.
Returns: Boolean - true if playing
#complete?
Check if the animation has completed (non-looping only).
Returns: Boolean - true if completed
#frame
Get the current frame index (from the frames array).
Returns: Integer - Current frame index
#frame=
Set the current frame index directly.
Parameters:
| Name | Type | Description |
|---|---|---|
index | Integer | Frame index (into frames array) |
Returns: Integer - The frame index
#fps
Get the frames per second.
Returns: Float - FPS
#fps=
Set the frames per second.
Parameters:
| Name | Type | Description |
|---|---|---|
value | Float | New FPS |
Returns: Float - The FPS value
Example:
# Speed up animation when player is running fast
def update(dt)
speed = calculate_movement_speed
# Scale animation FPS with movement speed (8-16 fps range)
#loop?
Check if the animation loops.
Returns: Boolean - true if looping
#loop=
Set whether the animation loops.
Parameters:
| Name | Type | Description |
|---|---|---|
value | Boolean | true to loop |
Returns: Boolean - The loop value
#count
Get the number of active sprite animations.
Returns: Integer - Number of active animations