MaxRects (default)
MaxRects is the default packing algorithm. It produces dense atlases by tracking a list of maximal free rectangles and scoring candidate placements under a configurable heuristic.How it works
The algorithm maintains a list of free rectangles covering all unoccupied atlas space. Initially the list contains one rectangle equal to the usable canvas (max dimensions minus border padding). For each sprite (processed largest-area-first):- Score every free rectangle against the sprite dimensions using the active heuristic
- Place the sprite at the best-scoring position
- Split every free rectangle that overlaps the placed footprint (including shape padding) into up to four non-overlapping sub-rectangles
- Prune any free rectangle that is fully contained within another free rectangle
Heuristics
- Best short side fit
- Best long side fit
- Best area fit
- Bottom left rule
- Contact point rule
best-short-side-fit (default) — Minimizes the shorter leftover dimension after placement. Tends to produce compact, roughly square packing.
Configuration
Technical details
Shape padding is handled by adding the padding value to the sprite’s footprint width and height before scoring and splitting. The actual sprite rectangle is stored without padding; the gap appears as unused space between sprites. Border padding offsets the initial free rectangle inward so all placed sprites respect the configured atlas edge margin. Atlas size is computed after packing as the bounding box of all placed sprites plus border padding, then rounded up to satisfysize_constraint. If force_square is set, width and height are both raised to the larger of the two.
Rotation is tested when allow_rotation is true and the sprite is not square. The rotated candidate is scored independently. The orientation with the better score wins. A rotated sprite is blitted 90° clockwise.
Free-rect pruning is O(n²) per placement. For atlases with thousands of sprites this is the dominant cost.
MaxRects maps directly to TexturePacker’s MaxRects algorithm. All five heuristics have the same names (except TexturePacker uses “Best” as a prefix).
Grid
The grid packer divides the atlas into uniform cells of equal size and places each sprite into the next available cell in row-major order (left to right, then top to bottom). Grid packing is the right choice for animation frame strips and tile sets where all sprites are the same size. Its regular layout simplifies runtime frame calculation — a loader can compute any frame’s position from its index with a single multiply, without parsing a data file.Configuration
- Automatic cell size
- Fixed cell size
Let FastPack compute cell size from the sprite set (uses the largest sprite’s dimensions):
There is no dedicated CLI flag for grid packing. Use a project file with
[algorithm] type = "grid".Example
Twenty 32×32 sprites packed into a 256-pixel-wide atlas withcell_width = 32, cell_height = 32:
Technical details
Whencell_width or cell_height is 0, FastPack measures every sprite and uses the maximum width and height respectively.
The number of columns is floor(max_width / cell_width). The atlas height grows to fit all rows needed for the full sprite set.
Despite the regular layout, FastPack still writes a full data file with exact frame rects. Sprites smaller than the cell have correct frame and sourceSize values, and pivot/nine-patch overrides work the same as with other algorithms.
TexturePacker calls this mode “Fixed Grid”. Cell-size derivation and row-major placement order match FastPack’s behavior.
Basic
The basic packer places sprites in horizontal strips. Starting from the top-left, it advances a cursor left-to-right across the row. When a sprite does not fit in the remaining row width, the cursor drops to the start of a new row below. Sprites within a row are top-aligned. Basic packing is fast but makes no attempt to minimize atlas area. Use it when pack speed is the priority, or as a quick sanity-check mode during development.Configuration
--pack-mode fast selects the basic packer. good and best both use MaxRects.Example
Five sprites of varying sizes packed with the basic algorithm:Technical details
Sprites are sorted by height descending before placement. This reduces wasted vertical space within rows by putting tall sprites together. The atlas width is the fullmax_width (default 4096); the basic packer does not search for a compact atlas width the way MaxRects does. The atlas height grows one row at a time until all sprites are placed.
TexturePacker’s “Basic” algorithm uses the same row-strip approach. Atlas dimensions may differ because TexturePacker searches for an optimal width; FastPack’s basic packer always uses the full
max_width.