https://github.com/lafriks/go-tiled
Go library to parse Tiled map editor file format (TMX) and render map to image
https://github.com/lafriks/go-tiled
go golang hacktoberfest rendering-2d-graphics tmx
Last synced: 8 months ago
JSON representation
Go library to parse Tiled map editor file format (TMX) and render map to image
- Host: GitHub
- URL: https://github.com/lafriks/go-tiled
- Owner: lafriks
- License: mit
- Created: 2017-01-25T13:33:28.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2025-01-07T10:25:31.000Z (about 1 year ago)
- Last Synced: 2025-04-08T12:07:45.940Z (9 months ago)
- Topics: go, golang, hacktoberfest, rendering-2d-graphics, tmx
- Language: Go
- Homepage:
- Size: 929 KB
- Stars: 215
- Watchers: 6
- Forks: 46
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# go-tiled
[](https://pkg.go.dev/github.com/lafriks/go-tiled)
[](https://cloud.drone.io/lafriks/go-tiled)
Go library to parse Tiled map editor file format (TMX) and render map to image. Currently supports only orthogonal finite maps rendering out-of-the-box.
## Installing
```sh
go get github.com/lafriks/go-tiled
```
You can use `go get -u` to update the package. You can also just import and start using the package directly if you're using Go modules, and Go will then download the package on first compilation.
## Basic Usage
```go
package main
import (
"fmt"
"os"
"github.com/lafriks/go-tiled"
"github.com/lafriks/go-tiled/render"
)
const mapPath = "maps/map.tmx" // Path to your Tiled Map.
func main() {
// Parse .tmx file.
gameMap, err := tiled.LoadFile(mapPath)
if err != nil {
fmt.Printf("error parsing map: %s", err.Error())
os.Exit(2)
}
fmt.Println(gameMap)
// You can also render the map to an in-memory image for direct
// use with the default Renderer, or by making your own.
renderer, err := render.NewRenderer(gameMap)
if err != nil {
fmt.Printf("map unsupported for rendering: %s", err.Error())
os.Exit(2)
}
// Render just layer 0 to the Renderer.
err = renderer.RenderLayer(0)
if err != nil {
fmt.Printf("layer unsupported for rendering: %s", err.Error())
os.Exit(2)
}
// Get a reference to the Renderer's output, an image.NRGBA struct.
img := renderer.Result
// Clear the render result after copying the output if separation of
// layers is desired.
renderer.Clear()
// And so on. You can also export the image to a file by using the
// Renderer's Save functions.
}
```
## Documentation
For further documentation, see or run:
```sh
godoc github.com/lafriks/go-tiled
```