A sprite sheet is a grid, and the last row is often not full: 45 frames on an 8 by 6 sheet leaves 3 empty cells. Cut every cell into the animation and those empty cells become frames where the effect disappears. In our Godot 4.7 test at 24 fps that was 0.125 s of nothing at the end of every loop, and a missing frame in the middle of a sheet made it blink halfway through. The script below builds the SpriteFrames from the grid and leaves out any cell where every pixel is transparent: 45 frames and 44 frames, no empty one.
The code
Save it as sheet_frames.gd and load it with const SheetFrames := preload("res://sheet_frames.gd"). Give it the sheet, the number of columns and rows, the speed and whether it loops, and set the result on your AnimatedSprite2D: $Effect.sprite_frames = SheetFrames.make(sheet, 8, 6, 24.0, false), then $Effect.play().
extends RefCounted
## Build SpriteFrames from a sprite sheet grid, in reading order, and skip the empty cells
## (a sheet of 8 x 6 cells with 45 frames has 3 empty ones at the end).
## const SheetFrames := preload("res://sheet_frames.gd")
## $Effect.sprite_frames = SheetFrames.make(preload("res://fx/explosion_sheet.png"), 8, 6, 24.0, false)
## $Effect.play()
static func make(sheet: Texture2D, columns: int, rows: int, fps := 24.0, loop := false, anim := &"default") -> SpriteFrames:
var frames := SpriteFrames.new()
if not frames.has_animation(anim):
frames.add_animation(anim)
frames.set_animation_speed(anim, fps)
frames.set_animation_loop(anim, loop)
var img := sheet.get_image()
if img.is_compressed():
img.decompress()
var cw := sheet.get_width() / columns
var ch := sheet.get_height() / rows
for r in rows:
for c in columns:
var rect := Rect2i(c * cw, r * ch, cw, ch)
if img.get_region(rect).is_invisible():
continue # nothing drawn in this cell
var cell := AtlasTexture.new()
cell.atlas = sheet
cell.region = Rect2(rect)
frames.add_frame(anim, cell)
return frames
What we measured
A sheet of 8 by 6 cells, 64 px each, with a square drawn in 45 of them, made in code so we knew which cells were empty. We counted the frames each way and checked each one for anything drawn, then played the result on a real AnimatedSprite2D. Two runs gave the same numbers.
- Every cell as a frame: 48 frames, 3 of them empty (the last 3), 0.125 s with nothing on screen in every loop at 24 fps.
- The script: 45 frames, none empty.
- The same sheet with frame 20 missing as well: every cell gave 48 frames with 4 empty, one of them in the middle of the effect, 0.167 s blank per loop. The script: 44 frames, none empty.
- The script's frames played once on an AnimatedSprite2D: animation_finished came after 1.80 s on frame 44, the 45th, and not one screen frame showed an empty cell. The last frame was drawn on screen, 144 lit pixels.
Why it happens
A grid has columns times rows cells, but an effect has as many frames as it has, and the last row is filled from the left. Cutting by the grid adds the leftover cells as real frames, so the animation plays them too, fully transparent. Image.is_invisible() tells you when every pixel of a cell has zero alpha, so those cells can be skipped, wherever they are.
What to change
- A cell that is meant to be empty, like a pause in a blinking light: keep it, by setting its duration instead with
SpriteFrames.set_frame(), or skip this check for that sheet. - Cells read left to right, top to bottom. A sheet laid out by columns needs the two loops swapped.
- The sheet's width and height should divide evenly by the columns and rows. If not, the cells drift by the leftover pixels.
- Removing the effect when it ends: animation_finished never fires. The same problem on particles: flipbook particles that blink out on empty cells.
- Thin lines from the next cell along the frame edges when the effect is scaled or moving: turn on filter_clip.
Ready-made 2D effects: HD VFX Sprite Sheets Vol 1 has 106 animated effects as transparent PNG sprite sheets for 2D engines, Godot 2D included.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: HD VFX Sprite Sheets Vol 1 has 106 animated effects as transparent PNG sprite sheets for 2D engines, Godot 2D included.
More how-tos for HD VFX Sprite Sheets Vol 1: GPUParticles2D not showing in Godot 4 · Transparent PNGs without a dark outline
More how-tos: Play, stop and remove effects
- An aura that comes back when the buff comes back
- A spawned effect that appears exactly where you hit
- Draw the hit effect over what it hit
- Remove a one-shot particle effect when it ends
- Fade out and stop looping particles
- Spawn a hit effect facing the surface
- Hit sparks from a pool of emitters
- Changing one particle effect's color changes all of them
- Particles that play the same way every time
- Freeze particles in mid-air
- Running dust and landing puffs
- Particles left behind by a moving object
- 2D particles follow the player or stay behind
- Footstep particles that match the ground
- A level up effect that plays while paused
- Hide particle effects far from the camera
- Death particles disappear when the enemy is freed
- Remove all particles at once
- Tire smoke that only shows when the car drifts
- Play a 2D sprite sheet effect once and remove it, even if its animation loops
- Sprite sheet frames without lines from the next cell