Sprite Compiler Overview¶
The Sprite Compiler is a tool that converts PNG images into PixelRoot32 sprite data formats. It provides both a graphical interface (GUI) and a command-line interface (CLI) to automate the process of creating sprite arrays from image files.
What It Does¶
The Sprite Compiler takes bitmap images (PNG) and converts them into C header files containing:
- Sprite data arrays: Optimized
uint16_tarrays for various formats. - Layered support: Generates multiple 1bpp layers for complex sprites.
- Packed formats: Supports 2bpp and 4bpp packed formats.
- Sprite sheets: Handles grid-based sprite sheets with auto-detection.
Key Features¶
✅ Format Support¶
- Layered (1bpp): Standard format, generates one array per color.
- 2bpp (4 colors): Packed format, 2 bits per pixel.
- 4bpp (16 colors): Packed format, 4 bits per pixel.
✅ GUI & CLI¶
- Modern GUI: Step-by-step card-based interface for easy configuration.
- Powerful CLI: Perfect for build scripts and automation.
✅ Sprite Sheets¶
Automatically split sprite sheets into individual sprites:
GUI Interface¶
The GUI is designed to be intuitive and follows a 5-step process:
- Input Image: Select your PNG source.
- Grid Settings: Define the cell size and offsets.
- Sprite Selection: Pick which cells to export.
- Export Settings: Choose the mode (Layered, 2bpp, 4bpp), set a Prefix, and choose the output path.
- About: Quick access to version info and credits (via the
?button). - Log: Technical feedback and performance alerts.
Input Requirements¶
Supported Formats¶
- PNG: Primary format (recommended)
- Indexed color PNG: Best for 1bpp conversion
- Grayscale PNG: Automatically converted to 1bpp
- RGB PNG: Converted using threshold or palette
Image Constraints¶
For 1bpp sprites: - Maximum width: 16 pixels - Height: Any (typically 8, 16, 32 pixels) - Colors: Black and white (or converted automatically)
For 2bpp sprites: - Maximum width: 16 pixels - Colors: Up to 4 colors
For 4bpp sprites: - Maximum width: 16 pixels - Colors: Up to 16 colors
Output Format¶
The compiler generates C header files with optimized arrays:
// Generated by PixelRoot32 Sprite Compiler
// Optional palette mapping if using custom colors
static const Color PLAYER_PALETTE_MAPPING[16] = {
(Color)0, (Color)1, (Color)2, (Color)3,
// ...
};
// Sprite data array (4bpp example)
static const uint16_t PLAYER_SPRITE_0_4BPP[] = {
0x0000, 0x1234, 0x5678, // Row 0
// ... more rows
};
Use Cases¶
1. Single Sprite Conversion¶
Convert a single image to a sprite:
2. Animation Frames¶
Convert multiple frames for animation:
3. Sprite Sheet Processing¶
Split a sprite sheet into individual sprites:
4. Batch Asset Processing¶
Process entire asset directories:
Workflow Integration¶
Typical Development Workflow¶
- Create sprites in your image editor (Aseprite, Piskel, GIMP, etc.)
- Save as PNG with appropriate dimensions
- Run compiler to generate header files
- Include headers in your PixelRoot32 project
- Use sprites in your game code
Automation Example¶
#!/bin/bash
# build-sprites.sh
# Compile all sprites
pr32-sprite-compiler assets/sprites/*.png --output-dir src/sprites/
# Continue with your build process
platformio run
Advantages Over Manual Creation¶
✅ Time Saving¶
- No manual bit pattern conversion
- Automatic format optimization
- Batch processing multiple sprites
✅ Accuracy¶
- Correct bit ordering
- Proper array formatting
- Valid C++ syntax
✅ Consistency¶
- Uniform naming conventions
- Standardized output format
- Consistent code structure
✅ Maintainability¶
- Easy to regenerate from source images
- Version control friendly
- Clear separation of assets and code
Limitations¶
- Width limit: 16 pixels for 1bpp (hardware constraint)
- Color depth: Limited by format (1bpp = 2 colors, 2bpp = 4 colors, etc.)
- File format: Primarily PNG (other formats may require conversion)
Next Steps¶
- Installation Guide - Set up the compiler
- Usage Guide - Learn how to use it
- Advanced Features - Explore advanced options
See Also¶
- Manual - Sprites and Animation - Using sprites in games
- Code Examples - Sprites - Sprite usage examples
- Available Tools - All PixelRoot32 tools