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
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
package main
import (
"fmt"
"os"
"github.com/lafriks/go-tiled"
"github.com/lafriks/go-tiled/render"
)
const mapPath = "maps/map.tmx"
func main() {
gameMap, err := tiled.LoadFile(mapPath)
if err != nil {
fmt.Printf("error parsing map: %s", err.Error())
os.Exit(2)
}
fmt.Println(gameMap)
renderer, err := render.NewRenderer(gameMap)
if err != nil {
fmt.Printf("map unsupported for rendering: %s", err.Error())
os.Exit(2)
}
err = renderer.RenderLayer(0)
if err != nil {
fmt.Printf("layer unsupported for rendering: %s", err.Error())
os.Exit(2)
}
img := renderer.Result
renderer.Clear()
}
Documentation
For further documentation, see https://pkg.go.dev/github.com/lafriks/go-tiled or run:
godoc github.com/lafriks/go-tiled