Gridwright Start for $1

Sprite Sheet Cutter Online: Split Sheets into PNG Frames

Split a sprite sheet into single PNG frames: read its cell size, margin and spacing, cut it in Godot 4 with a script, or let a sprite sheet cutter do it.

Sprite Sheet Cutter at work
Sprite Sheet Cutter at work: Single frames from a sprite sheet.

You have a character sheet and you need the frames apart: your engine or animation tool wants one PNG per frame, or you only need to know where each frame sits. You type 32 x 32 into the slicer and the first column looks fine. By the fourth column every frame has a strip of the next one down its side, and the last column is cut in half.

The usual reason is a border round the sheet, a gap between the frames, or both, and the slicer assumed neither. This guide shows how to read a sheet's grid, how to cut it in Godot 4, with a script for the cases the editor makes slow, and how the Sprite Sheet Cutter splits a sheet into frames in seconds.

The four numbers every sheet has

A sprite sheet is a grid, and four numbers describe it:

Farm RPG
Farm RPG: 16x16 farming RPG kit: a working farmer in 4 directions, a character creator, seasons, animals. One of the 150 packs in Gridwright.
  • Cell size: the width and height of one frame, such as 32 x 32 or 32 x 48.
  • Offset, also called margin: the empty border before the first frame, from the left and from the top.
  • Spacing, also called padding or separation: the gap between one frame and the next, across and down.
  • Columns and rows: how many frames fit.

Get the first three right and the last one follows: columns = (sheet width - offset + spacing) / (cell width + spacing), rounded down. Take a sheet 274 px wide with a 2 px border, 2 px gaps and 32 px frames: (274 - 2 + 2) / 34 = 8.06, so 8 columns. The 0.06 left over is the border on the right.

To read the numbers, open the sheet in an image editor that shows the cursor position, zoom in and find two pixels: the top-left pixel of the first frame gives the offset, and the top-left pixel of the second frame gives the cell size plus the spacing. The width is a hint too: 256 px is probably 8 frames of 32 with no gaps, while 274 or 263 px means a border, gaps or both.

What goes wrong when the grid is off

  • The cut drifts. The first frame is right and each column is a little further off. The sheet has spacing and the slicer is set to none.
  • Every frame is shifted by the same amount. The offset is missing, so each cut starts a few pixels early.
  • Blank frames in the animation. The last row has 5 frames in a grid of 8, and the 3 empty cells play as a flicker at the end of the loop.
  • Frames jitter in place. The cut is right, but the character sits at a different spot in each cell. No slicer fixes that, so watch the animation first.
  • Every frame has a coloured box round it. The sheet was saved on flat magenta or green instead of transparency. Clear it first with the Pixel Art Background Remover.
Pixel Art Background Remover: Transparent sprites from a flat background
Pixel Art Background Remover: Transparent sprites from a flat background. Included in Gridwright.

Cutting a sheet in Godot 4

Godot has no command that splits a sheet into PNG files, but three places in the editor read a grid:

Low-Poly Kit Fantasy Village
Low-Poly Kit Fantasy Village: 116 low poly 3D models for a fantasy village: houses, trees, props. One of the 150 packs in Gridwright.
  • Sprite2D has Hframes and Vframes under Animation. They divide the texture evenly, with no setting for a border or gaps.
  • AnimatedSprite2D: in the SpriteFrames panel, Add Frames from Sprite Sheet opens Create Frames from Sprite Sheet, with Horizontal, Vertical, Size, Separation, Offset and Auto Slice. You click the frames of one animation, add them, and repeat for the next row. The AnimatedSprite2D guide walks through it.
  • The region editor (a Sprite2D with Region on, then Edit Region) has a Snap Mode called Grid Snap, with Offset, Step and Separation, and an Auto Slice mode. It picks one rectangle at a time.

When a sheet has a dozen rows, or new sheets arrive every week, a script is quicker. This one cuts a sheet with any offset and spacing into a SpriteFrames, one looping animation per row, skips empty cells, and can save every frame as a PNG. Save it as sheet_cutter.gd anywhere in your project:

class_name SheetCutter
## Cuts a sprite sheet on a grid that has a margin (offset) and spacing between frames.

## The rectangle of every whole cell, one array per row. Cells that run past the edge are left out.
static func grid(size: Vector2i, cell: Vector2i, offset := Vector2i.ZERO, spacing := Vector2i.ZERO) -> Array:
	var step := cell + spacing
	var cols := floori(float(size.x - offset.x + spacing.x) / step.x)
	var rows := floori(float(size.y - offset.y + spacing.y) / step.y)
	var out := []
	for r in rows:
		var row: Array[Rect2i] = []
		for c in cols:
			row.append(Rect2i(offset + Vector2i(c, r) * step, cell))
		out.append(row)
	return out


## A SpriteFrames with one looping animation per row: row_0, row_1 and so on. Empty cells are skipped.
static func sprite_frames(sheet: Texture2D, cell: Vector2i, offset := Vector2i.ZERO, spacing := Vector2i.ZERO, fps := 8.0) -> SpriteFrames:
	var img := sheet.get_image()
	var frames := SpriteFrames.new()
	frames.remove_animation(&"default")
	var rows := grid(img.get_size(), cell, offset, spacing)
	for r in rows.size():
		var anim := StringName("row_%d" % r)
		for rect: Rect2i in rows[r]:
			if img.get_region(rect).is_invisible():
				continue  # a blank cell at the end of a row
			if not frames.has_animation(anim):
				frames.add_animation(anim)
				frames.set_animation_speed(anim, fps)
			var tex := AtlasTexture.new()
			tex.atlas = sheet
			tex.region = Rect2(rect)
			frames.add_frame(anim, tex)
	return frames


## Every cell that isn't empty saved as its own PNG, named <name>_<row>_<column>.png. Returns how many were saved.
static func save_frames(sheet: Image, cell: Vector2i, folder: String, name := "frame", offset := Vector2i.ZERO, spacing := Vector2i.ZERO) -> int:
	DirAccess.make_dir_recursive_absolute(folder)
	var saved := 0
	var rows := grid(sheet.get_size(), cell, offset, spacing)
	for r in rows.size():
		for c in rows[r].size():
			var frame := sheet.get_region(rows[r][c])
			if frame.is_invisible():
				continue
			frame.save_png("%s/%s_%d_%d.png" % [folder, name, r, c])
			saved += 1
	return saved

To cut a sheet once and keep the result, run it from the editor. Open this script in the script editor and choose File > Run (Ctrl+Shift+X):

@tool
extends EditorScript

# File > Run in the script editor (Ctrl+Shift+X) cuts the sheet once and saves the results next to it.
func _run() -> void:
	var sheet := load("res://art/knight.png") as Texture2D
	var cell := Vector2i(32, 32)
	var offset := Vector2i(2, 2)
	var spacing := Vector2i(2, 2)
	var frames := SheetCutter.sprite_frames(sheet, cell, offset, spacing, 10.0)
	ResourceSaver.save(frames, "res://art/knight_frames.tres")
	var n := SheetCutter.save_frames(sheet.get_image(), cell, "res://art/knight_frames", "knight", offset, spacing)
	print("Saved %d frames" % n)

It saves knight_frames.tres next to the sheet and a folder of frames named knight_<row>_<column>.png. Or cut at run time, which suits a sheet you are still redrawing:

extends AnimatedSprite2D

func _ready() -> void:
	sprite_frames = SheetCutter.sprite_frames(preload("res://art/knight.png"), Vector2i(32, 32), Vector2i(2, 2), Vector2i(2, 2))
	play(&"row_0")

We ran all three in Godot 4.7.2 on a 274 x 104 test sheet with a 2 px border, 2 px gaps and a short last row: 21 frames came out, every region on its cell to the pixel, and the 3 empty cells skipped. The script reads the sheet's pixels with get_image(), so keep the sheet on Godot's default 2D import.

The fast way: the Sprite Sheet Cutter

The Sprite Sheet Cutter does the same job with no code, and you see every cut first. It runs in your browser and never uploads your sheet, so it's safe for art from a game you haven't announced.

  1. Drop your sheet (PNG, GIF or WebP) on the box, or open ours, a walking adventurer.
  2. Check the first guess. It guesses a square cell size from where the sprites sit, since a line between frames cuts through little and a line through a sprite cuts through a lot. On 446 sheets from our own packs it found the right size for 438. A sheet with no transparent pixel, such as one on flat magenta, is read by its background colour. On a sheet with a border or gaps, set the numbers yourself.
  3. Set the grid. By cell size takes the width and height of one frame. By rows & columns takes the counts and works the cell size out. Then set Offset X (margin), Offset Y (margin), Spacing X (padding) and Spacing Y (padding). Yellow lines show every cut over the sheet, and the summary reads, for example, "8 x 3 cells of 32 x 32 px".
  4. Skip the blanks. Skip empty (fully transparent) cells is on from the start and shades the empty cells, so a short last row adds no blank frames.
  5. Watch it play. In the Animation preview, pick All frames or one row, set First frame and Last frame (0 = all), and set the speed from 1 to 30 fps. A wrong cut shows here as a frame that jumps.
  6. Download. Download N frames (ZIP) gives you everything below, and JSON map only gives just the rectangles.
Your game, looking finished

Every Gridwright asset pack, made to fit together, and all 44 tools for the fiddly work, with every new release, for $17 a month. Try it in your own game first: 3 days for $1 with every tool and up to 10 packs. Cancel any time.

Start: 3 days for $1 See everything it includes

What is in the ZIP

  • The sheet itself as a PNG (a GIF or WebP goes in as a PNG).
  • frames/: every frame as its own PNG, named <name><row><column>.png and counted from 0.
  • <name>_frames.json: the sheet's size, the speed, and every frame's row, column, x, y, width and height.
  • <name>_frames.tres: a Godot 4 SpriteFrames with one looping animation per row (row_0, row_1 and on) at the speed you set in the preview. Each frame is an AtlasTexture region of the sheet.
  • A README with the frame size and what each file is.

Keep the .tres in the same folder as the sheet's PNG, because it finds the sheet by that relative path. We loaded the tool's .tres for the same test sheet in Godot 4.7.2, and every region sat on its cell.

Use the frames in Godot 4

  1. Copy the unzipped folder into your project.
  2. Add an AnimatedSprite2D and drag the .tres from the FileSystem dock onto its Sprite Frames property.
  3. In the SpriteFrames panel, rename row_0 and the rest to idle, walk and attack, turn looping off for one-shot animations, and press Autoplay on Load on idle.
  4. If the frames look soft, set Project Settings > Rendering > Textures > Canvas Textures > Default Texture Filter to Nearest.

Engines and tools that read single PNG files can use frames/ and the JSON map as they are.

FAQ

Can it cut a sheet whose frames are different sizes?

It cuts a regular grid, every cell the same size. A packed atlas with frames of different sizes comes with its own data file (JSON or XML) that lists each rectangle, and that file is what your engine should read.

Does it upload my sheet?

No. The sheet is read and cut in your browser, and the ZIP is made there too.

Cut your first sheet

Open the Sprite Sheet Cutter, drop a sheet and line the yellow cuts up between the frames. Going the other way, from loose frames to one sheet, is the Sprite Sheet Maker's job. If you'd rather start from sheets already on a clean grid, Street Brawlers has one sheet per fighter, with each row an animation in 64x64 cells, so it cuts straight into one animation per row. Both tools and the pack are part of Gridwright: 44 tools and 150 asset packs, 3 days for $1, then $17 a month.

Sprite Sheet Maker: One sprite sheet from many frames
Sprite Sheet Maker: One sprite sheet from many frames. Included in Gridwright.
Your game, looking finished

Every Gridwright asset pack, made to fit together, and all 44 tools for the fiddly work, with every new release, for $17 a month. Try it in your own game first: 3 days for $1 with every tool and up to 10 packs. Cancel any time.

Start: 3 days for $1 See everything it includes