The tiled package provides Data and DataTile types to represent tile layer data from TMX files.
Data: Represents the <data> element of a tile layer. It contains metadata about how the tile data is stored, including Encoding (e.g., "base64", "csv") and Compression (e.g., "gzip", "zlib").DataTile: Represents an individual tile, containing a GID (Global ID).
Depending on the Encoding used in the TMX file, the Data struct will be populated in one of two ways:
- Encoded Data: If
Encoding is set to "base64" or "csv", the RawData field is populated with the raw bytes from the XML. - XML Tile Elements: If
Encoding is not set, the DataTiles slice is populated with individual DataTile objects parsed from <tile gid="N"/> elements.
type Data struct {
Encoding string `xml:"encoding,attr"` // e.g., "base64", "csv"
Compression string `xml:"compression,attr"` // e.g., "gzip", "zlib"
RawData []byte `xml:",innerxml"` // Populated if Encoding is "csv" or "base64"
DataTiles []DataTile `xml:"tile"` // Populated if Encoding is not set
}
type DataTile struct {
GID uint32 `xml:"gid,attr"` // The global tile ID
}