#tiled #map #tile #maps #loading #layer #tileset

yanked tmx

TMX is a library for loading Tiled maps in Rust

7 releases

0.3.1 May 28, 2020
0.3.0 May 28, 2020
0.2.2 May 26, 2020
0.1.2 Apr 30, 2020

#15 in #tileset

22 downloads per month

MIT license

38KB
750 lines

TMX

Build Status Crates.io Docs License

TMX is a library for loading Tiled (XML and JSON) maps in Rust.

Usage

cargo add tmx

Examples

Loading a Map

use tmx::Map;

fn main() -> Result<(), Box<dyn Error>> {
    let map = r##"
    <?xml version="1.0" encoding="UTF-8"?>
    <map version="1.2" tiledversion="1.3.3" orientation="isometric" renderorder="right-down" width="4" height="4" tilewidth="16" tileheight="16" infinite="0" nextlayerid="2" nextobjectid="1">
     <tileset firstgid="1" name="test" tilewidth="16" tileheight="16" tilecount="256" columns="16">
      <image source="tiles16.png" width="256" height="256"/>
     </tileset>
     <layer id="1" name="Tile Layer 1" width="4" height="4">
      <data encoding="csv">
    1,2684354561,1,2147483649,
    1610612737,3221225473,1073741825,3221225473,
    2147483649,3758096385,1073741825,536870913,
    536870913,1073741825,3758096385,2147483649
    </data>
     </layer>
    </map>
    "##;

    let map = Map::from_xml(map)?;
    println!("{:?}", map);

    Ok(())
}

Loading a Tileset

use tmx::Tileset;

fn main() -> Result<(), Box<dyn Error>> {
    let tileset = r##"
    <?xml version="1.0" encoding="UTF-8" ?>
<tileset version="1.2" tiledversion="1.3.3" name="tiles16" tilewidth="16" tileheight="16" tilecount="256" columns="16">
    <image source="tiles16.png" width="256" height="256" />
    <tile id="0" type="Solid" />
    <tile id="1" type="Solid" />
    <tile id="2" type="Solid" />
    <tile id="3" type="OneWay" />
</tileset>
    "##;

    let tileset = Tileset::from_xml(tileset)?;
    println!("{:?}", tileset);

    Ok(())
}

See the docs for more information.

TMX Map Format Support

Element Support
<map> ✅ Full
<editorsettings> 🛑 None
- <chunksize> 🛑 None
- <export> 🛑 None
<tileset> ⚠️ Partial
- <tileoffset> 🛑 None
- <grid> 🛑 None
- <image> ✅ Full
- <terraintypes> 🛑 None
- - <terrain> 🛑 None
- <tile> ✅ Full
- - <animation> ✅ Full
- <wangsets> 🛑 None
- - <wangset> 🛑 None
<layer> ✅ Full
- <data> ✅ Full
- <chunk> ✅ Full
- <tile> ✅ Full
<objectgroup> 🛑 None
- <object> 🛑 None
- <ellipse> 🛑 None
- <point> 🛑 None
- <polygon> 🛑 None
- <polyline> 🛑 None
- <text> 🛑 None
<imagelayer> 🛑 None
<group> 🛑 None
<properties> 🛑 None
- <property> 🛑 None

Features

The following features are available and enabled by default.

Feature Description
xml Allows loading XML maps.
base64-data Allows loading maps where the Tile Layer Format is Base64 (uncompressed).
gzip-data Allows loading maps where the Tile Layer Format is Base64 (gzip compressed).
zlib-data Allows loading maps where the Tile Layer Format is Base64 (zlib compressed).
zstd-data Allows loading maps where the Tile Layer Format is Base64 (Zstandard compressed).

License

MIT

Dependencies

~1.8–4MB
~69K SLoC