Two ways to load a sprite sheet in LibGDX
LibGDX supports two clean workflows for 2D sprite animation: splitting a uniform equal-cell PNG grid directly with TextureRegion.split(), or packing frames into a .atlas file for TextureAtlas. SheetSlicer exports clean, equal-cell transparent PNG sheets and frame ZIPs right in your browser, so you can plug directly into either route without resizing or manual cropping.
1. Prepare an equal-cell PNG sheet in SheetSlicer
Open the Sprite Sheet Slicer for an existing sheet or the Sprite Sheet Packer if you have separate PNG frames. Remove any solid background with the edge-connected color key, enable trim and bottom (feet) or center alignment, and choose your column count and padding.
Write down the exported cell width and cell height displayed in the preview panel. Every cell in SheetSlicer's PNG output has identical pixel dimensions and includes its internal padding, with zero outside border margin or inter-cell gutter — exactly what TextureRegion.split() expects.
2. Quickest path: TextureRegion.split() for uniform grids
Place the exported PNG inside your LibGDX assets/ directory (for example assets/hero_walk.png). Then slice it in code using your exported cell width and cell height:
Texture sheet = new Texture(Gdx.files.internal("hero_walk.png"));
// For crisp pixel art, use Nearest filtering:
sheet.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
TextureRegion[][] grid = TextureRegion.split(sheet, cellWidth, cellHeight);
TextureRegion[] frames = new TextureRegion[frameCount];
int idx = 0;
for (int row = 0; row < grid.length && idx < frameCount; row++) {
for (int col = 0; col < grid[row].length && idx < frameCount; col++) {
frames[idx++] = grid[row][col];
}
}
Animation<TextureRegion> walkAnim = new Animation<>(1f / 12f, frames);
Always cap the loop at your real frameCount if the final row of your grid has trailing empty cells.
3. When you need a LibGDX .atlas (TextureAtlas)
For larger projects that combine multiple characters, UI icons, and backgrounds into one draw call, export individual PNG frames (ZIP) from SheetSlicer (named hero_walk_0.png, hero_walk_1.png, etc.) and feed that folder into LibGDX's official TexturePacker tool (gdx-tools). Because SheetSlicer already trimmed, centered, and removed backgrounds from every pose, TexturePacker generates a clean .atlas + .png pair ready for atlas.findRegions("hero_walk") without frame jitter.
SheetSlicer does not output a native .atlas text descriptor directly; use TextureRegion.split() for single-sheet animations or feed the cleaned PNG ZIP into LibGDX TexturePacker for multi-sprite atlases.
4. Common LibGDX sprite sheet pitfalls
- Texture bleeding on linear filtering: For pixel art, set
TextureFilter.Neareston both min and mag filters, or add 1–2 px of transparent padding in SheetSlicer before exporting. - Wrong frame height after trimming: Always pass SheetSlicer's exported cell width and height into
TextureRegion.split(), not the original uncleaned image dimensions. - Power-of-two sizing: Modern OpenGL ES 2.0/3.0 (LibGDX default) handles non-power-of-two textures without error, though keeping sheets under 2048 × 2048 ensures broad mobile GPU compatibility. See Does a Sprite Sheet Need Power-of-Two Dimensions?.