Godot 4: AnimationPlayer from a PNG Sequence

A folder of numbered PNGs is the most common output from an AI render, a Blender export, or a GIF splitter. Godot can animate it two ways:

  1. Pack the frames into one sheet and animate a frame property on a Sprite2D.
  2. Keep the PNGs separate and animate the texture property.

The first is almost always better for a game character. The second is useful for a short UI sequence or a handful of frames.

Path A: one sheet, one frame track

This is the recommended path.

1. Pack the frames

Use the sheet maker to pack the PNGs into a grid with uniform cells and 2 px padding. Keep the JSON; it tells you the columns, rows, and frame size.

If the frames have transparent edges, turn on trimming with uniform bounds so the character does not jitter.

2. Import the sheet

3. Set up the Sprite2D

  1. Add a Sprite2D and assign the sheet as its texture.
  2. Set Hframes and Vframes to the grid dimensions.
  3. The frame property now selects a cell.

4. Build the animation

  1. Add an AnimationPlayer.
  2. Create an animation, for example run.
  3. Add a track for the Sprite2D’s frame property.
  4. Insert keys 0, 1, 2, … at the timing you want.
  5. Set the track’s update mode to Discrete (not continuous).
  6. Enable looping on the animation.
extends Sprite2D

@onready var player: AnimationPlayer = $AnimationPlayer

func _ready() -> void:
    player.play("run")

The discrete update mode is the one people miss. With continuous interpolation, Godot tries to blend frame 3.4, which is not a frame.

Path B: separate PNGs, texture track

Use this when you have a small number of frames that do not share a grid, or when the frames are UI elements of different sizes.

  1. Import the PNGs into the project.
  2. Add a Sprite2D.
  3. Add an AnimationPlayer, create an animation.
  4. Add a track for the Sprite2D’s texture property.
  5. Insert a key at each time, assigning the corresponding texture.
  6. Set the track to Discrete.
  7. Enable looping if needed.
extends Sprite2D

@onready var player: AnimationPlayer = $AnimationPlayer

func play_sequence() -> void:
    player.play("ui_intro")

This works, but each PNG is a separate texture. For 30 character frames, that is 30 texture objects instead of one sheet, and more import bookkeeping. Pack them when you can.

Which node should own the animation?

Situation Use
Simple character loop AnimatedSprite2D + SpriteFrames
Animation with hitboxes, sounds, VFX AnimationPlayer
Short UI sequence AnimationPlayer (texture or frame track)
Many animations with blending AnimationTree

The full comparison is in AnimatedSprite2D vs AnimationPlayer.

Timing and frame order

If the frames are numbered 0001, 0002, … sort numerically, not lexicographically. frame_10.png sorts before frame_2.png in a naive string sort. The sheet maker uses natural sort.

Common problems

Symptom Cause Fix
Frames blend into each other Track update is continuous Set it to Discrete
Animation plays too fast Keys are one frame apart at the wrong FPS Space keys by 1/FPS
Only the first frame shows frame track has one key Add a key per frame
Frames are out of order Lexicographic sort Rename or pack with natural sort
Texture swap is offset Different image sizes Use a uniform sheet instead
Sprite is blurry Filter on Filter off for pixel art
Edge line appears No padding Add padding/extrude

When to automate the setup

For one animation, the editor is fine. For dozens, generating the resource is faster and less error-prone. The SpriteFrames generator writes a .tres directly; for AnimationPlayer, a small editor script can create tracks, but that is a larger project.

A practical middle ground: use SpriteFrames for the character, and AnimationPlayer only for the timeline events. You get simple frame data and precise gameplay timing.

FAQ

Can I use a GIF directly? Not as a texture. Split it into frames or a sheet first; the sheet maker can decode a GIF in Chrome/Edge.

Do I need to import every PNG separately? Only for the texture-track path. The sheet path uses one texture.

How do I loop the animation? Enable looping on the AnimationPlayer animation. For a one-shot, leave it off and connect animation_finished.

Can I change speed at runtime? Yes: player.speed_scale = 1.5. It affects all tracks in that player.

What is the difference from AnimatedSprite2D? AnimatedSprite2D plays frame data; AnimationPlayer animates properties, including frames. Use the timeline when you need more than frames.


Next: Sprite sheet vs texture atlas — the vocabulary behind both paths.