Skip to content

nexovec/go-tiled

This branch is up to date with lafriks/go-tiled:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

be90f06 · Jan 7, 2025

History

77 Commits
Mar 14, 2023
Dec 5, 2022
Mar 15, 2023
Dec 5, 2022
Mar 15, 2023
Jan 7, 2025
Nov 11, 2020
Nov 11, 2020
Nov 11, 2020
Aug 12, 2022
Apr 23, 2019
Jan 26, 2017
Jul 21, 2024
Aug 11, 2022
Aug 12, 2022
Jan 7, 2025
Jan 7, 2025
Jul 21, 2024
Dec 5, 2022
Dec 5, 2022
Jan 7, 2025
Jul 7, 2023
Oct 17, 2020
Jul 7, 2023
Jul 7, 2023
Mar 14, 2023
Jul 7, 2023
Jan 14, 2022
Jul 16, 2023
Jan 7, 2025
Mar 30, 2021
Jul 25, 2023
Jan 7, 2025
Jul 21, 2024

Repository files navigation

go-tiled

PkgGoDev Build Status

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" // 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 https://pkg.go.dev/github.com/lafriks/go-tiled or run:

godoc github.com/lafriks/go-tiled

About

Go library to parse Tiled map editor file format (TMX) and render map to image

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%