https://github.com/fzipp/texturepacker
Read sprite sheets created and exported as JSON by TexturePacker.
https://github.com/fzipp/texturepacker
go golang sprite-sheet spritesheet texture-atlas texture-packer texturepacker
Last synced: 10 months ago
JSON representation
Read sprite sheets created and exported as JSON by TexturePacker.
- Host: GitHub
- URL: https://github.com/fzipp/texturepacker
- Owner: fzipp
- License: bsd-3-clause
- Created: 2020-02-21T03:27:44.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2022-06-05T05:16:11.000Z (about 4 years ago)
- Last Synced: 2025-04-11T18:22:29.494Z (about 1 year ago)
- Topics: go, golang, sprite-sheet, spritesheet, texture-atlas, texture-packer, texturepacker
- Language: Go
- Size: 58.6 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# texturepacker
Package texturepacker reads sprite sheets created and exported as JSON by
[TexturePacker](https://www.codeandweb.com/texturepacker).
Add it to a module as a dependency via:
```
go get github.com/fzipp/texturepacker
```
## Documentation
Package documentation is available [on pkg.go.dev](https://pkg.go.dev/github.com/fzipp/texturepacker?tab=doc).
## Example usage
Create a sprite sheet with TexturePacker and and save it in "JSON (Hash)" format.

```go
package main
import (
"image"
_ "image/png"
"log"
"os"
"github.com/fzipp/texturepacker"
)
func main() {
sheet, err := texturepacker.SheetFromFile("ExampleSheet.json", texturepacker.FormatJSONHash{})
if err != nil {
log.Fatal(err)
}
imageFile, err := os.Open(sheet.Meta.Image)
if err != nil {
log.Fatal(err)
}
defer imageFile.Close()
img, _, err := image.Decode(imageFile)
sheetImage, ok := img.(image.RGBA)
if !ok {
log.Fatal("expected RGBA image")
}
for name, sprite := range sheet.Sprites {
spriteImage := sheetImage.SubImage(sprite.Frame)
// ...
}
}
```
## License
This project is free and open source software licensed under the
[BSD 3-Clause License](LICENSE).