Resource Embedding
Embed game assets into your binary for portable distribution.
Quick Setup
Add to the top of main.go:
//go:generate go run github.com/drpaneas/pigo8/cmd/embedgen -dir .
Then build:
go generate
go build
Your executable now includes all assets.
What Gets Embedded
The embedgen tool detects and embeds:
spritesheet.json- Sprite datamap.json- Map datapalette.hex- Custom palettemusic*.wav- Audio files
Manual Embedding
For custom control, create embed.go:
package main
import (
"embed"
p8 "github.com/drpaneas/pigo8"
)
//go:embed spritesheet.json map.json
var resources embed.FS
func init() {
p8.RegisterEmbeddedResources(
resources,
"spritesheet.json",
"map.json",
"", // No palette
)
}
Loading Priority
PIGO8 loads resources in this order:
- Current directory (highest priority)
- Common subdirectories:
assets/,resources/,data/,static/ - Embedded resources
- Library defaults (lowest priority)
This allows local files to override embedded resources during development.
Custom Palettes
Create palette.hex with hex colors:
c60021
e70000
e76121
e7a263
Color 0 is automatically transparent, colors shift to start at index 2.
Complete Example
Project structure:
my-game/
├── main.go
├── embed.go # Auto-generated
├── spritesheet.json
├── map.json
├── palette.hex
└── music1.wav
main.go:
//go:generate go run github.com/drpaneas/pigo8/cmd/embedgen -dir .
package main
import p8 "github.com/drpaneas/pigo8"
type game struct{}
func (g *game) Init() {}
func (g *game) Update() {}
func (g *game) Draw() { p8.Cls(1) }
func main() {
p8.InsertGame(&game{})
p8.Play()
}
Build and distribute:
go generate
go build -o my-game
./my-game # Works anywhere!