Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kangaroux/go-spritesheet
Use YAML to make working with sprite sheets easy. Compatible with ebiten
https://github.com/kangaroux/go-spritesheet
ebiten game game-development golang sprites spritesheet yaml
Last synced: 4 months ago
JSON representation
Use YAML to make working with sprite sheets easy. Compatible with ebiten
- Host: GitHub
- URL: https://github.com/kangaroux/go-spritesheet
- Owner: Kangaroux
- License: mit
- Created: 2021-06-19T05:24:59.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-06-20T13:54:05.000Z (over 3 years ago)
- Last Synced: 2024-10-15T17:38:25.386Z (4 months ago)
- Topics: ebiten, game, game-development, golang, sprites, spritesheet, yaml
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 12
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-spritesheet
[![Go Reference](https://pkg.go.dev/badge/github.com/kangaroux/go-spritesheet.svg)](https://pkg.go.dev/github.com/kangaroux/go-spritesheet)
Use YAML to describe your sprite sheet and give your sprites names. `go-spritesheet` will take care of the math for each sprite location, as well as provide a map for easy sprite lookups.
## Using With Ebiten
`go-spritesheet` pairs nicely with a library like [ebiten](https://github.com/hajimehoshi/ebiten).
```go
// Load the config
sheet, err := spritesheet.OpenAndRead("spritesheet.yml")if err != nil {
panic(err)
}// Load the image
img, _, err := ebitenutil.NewImageFromFile(sheet.Image)if err != nil {
panic(err)
}sprites := sheet.Sprites()
// Get the sprite
s := img.SubImage(sprites["mySprite"].Rect())
```## YAML Example
```yaml
image: hero.pngrows: 3
cols: 4
size: 16sprites: [
idle_1, idle_2, idle_3, idle_4,
run_1, run_2, run_3, run_4,
atk_1, atk_2, atk_3, atk_4
]
```## Config Format
- `image`: The path to your sprite sheet image.
- `rows`: The number of rows in the sprite sheet.
- `cols`: The number of columns in the sprite sheet.
- `size`: The size of each sprite, in pixels.
- `sprites`: A list of sprite names.
- Names must be unique.
- Must contain `0` to `n` entries, where `n` is `rows*cols`
- Using an underscore `_` skips the sprite. Useful if you have "holes" in your sprite sheet.