Categorygithub.com/lafriks/go-tiled
modulepackage
0.13.0
Repository: https://github.com/lafriks/go-tiled.git
Documentation: pkg.go.dev

# README

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

# Packages

No description provided by the author
Package render can be used to render parsed map to image.

# Functions

LoadFile function loads tiled map in TMX format from file.
LoadReader function loads tiled map in TMX format from io.Reader baseDir is used for loading additional tile data, current directory is used if empty.
NewHexColor is a shorthand to build a HexColor.
ParseHexColor converts hex color strings into HexColor structures This function can handle colors with and withouth optional alpha channel The leading '#' character is not required for backwards compatibility with Transparency Tiled filed https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#image.
WithFileSystem returns an option to load level from a passed filesystem.

# Constants

AxisX is X axis.
AxisY is Y axis.
Bottom represents the bottom part of the tile.
BottomLeft represents the bottom left part of the tile.
BottomRight represents the bottom right part of the tile.
Left represents the left part of the tile.
Right represents the right part of the tile.
StaggerIndexEven is even stagger index.
StaggerIndexOdd is odd stagger index.
Top represents the top part of the tile.
TopLeft represents the top left part of the tile.
TopRight represents the top right part of the tile.

# Variables

ErrEmptyLayerData error is returned when layer contains no data.
ErrInvalidDecodedTileCount error is returned when layer data has invalid tile count.
ErrInvalidObjectPoint error is returned if there is error parsing object points.
ErrInvalidTileGID error is returned when tile GID is not found.
ErrUnknownCompression error is returned when file contains invalid compression method.
ErrUnknownEncoding error is returned when kayer data has unknown encoding.
NilLayerTile is reusable layer tile that is nil.

# Structs

AnimationFrame is single frame of animation.
Data is raw data.
DataTile defines the value of a single tile on a tile layer.
Ellipse is used to mark an object as an ellipse.
Group is a group layer, used to organize the layers of the map in a hierarchy.
HexColor handles the conversion between hex color strings in form #AARRGGBB to color.RGBA structure.
Image source.
ImageLayer is a layer consisting of a single image.
Layer is a map layer.
LayerTile is a layer tile.
Map contains three different kinds of layers.
Object is used to add custom information to your tile map, such as spawn points, warps, exits, etc.
ObjectGroup is in fact a map layer, and is hence called "object layer" in Tiled Qt.
Point is point.
Polygon object is made up of a space-delimited list of x,y coordinates.
PolyLine follows the same placement definition as a polygon object.
Property is used for custom properties.
Template is used for custom properties.
Terrain type.
Text contains a text and attributes such as bold, color, etc.
Tileset is collection of tiles.
TilesetTile information.
TilesetTileOffset is used to specify an offset in pixels, to be applied when drawing a tile from the related tileset.
WangColor that can be used to define the corner and/or edge of a Wang tile.
WangSet defines a list of corner colors and a list of edge colors, and any number of Wang tiles using these colors.
WangTile by referring to a tile in the tileset and associating it with a certain Wang ID.

# Type aliases

Axis type.
LoaderOption is used with LoadReader and LoadFile functions to pass additional options.
Points is array of points.
Properties wraps any number of custom properties.
StaggerIndexType is stagger axis index type.
WangPosition Wang Color mapping to position.
WangSets contains the list of Wang sets defined for this tileset.