rs-tiled

toml tiled = "0.11.1"

Rust Crates.io Docs Status dependency status

A crate for reading TMX (map) and TSX (tileset) files from the Tiled Map Editor into Rust. It provides a huge set of features as well as a strong wrapper over internal features such as GIDs.

Documentation is available on docs.rs.

Code contributions are welcome as are bug reports, documentation, suggestions and criticism.

The minimum supported TMX version is 0.13.

Example

```rust use tiled::Loader;

fn main() { let mut loader = Loader::new(); let map = loader.loadtmxmap("assets/tiledbase64zlib.tmx").unwrap(); println!("{:?}", map); println!("{:?}", map.tilesets()[0].get_tile(0).unwrap().probability);

let tileset = loader.load_tsx_tileset("assets/tilesheet.tsx").unwrap();
assert_eq!(*map.tilesets()[0], tileset);

}

```

WASM

The crate supports WASM, but since it does not currently support asynchronous loading, there are some gotchas.

tiled = { version = ".....", features = ["wasm"] } ```

struct MyReader;

impl tiled::ResourceReader for MyReader { type Resource = Cursor<&'static [u8]>; type Error = std::io::Error;

// really dumb example implementation that just keeps resources in memory
fn read_from(&mut self, path: &std::path::Path) -> std::result::Result<Self::Resource, Self::Error> {
    if path == std::path::Path::new("my_map.tmx") {
        Ok(Cursor::new(include_bytes!("../assets/tiled_xml.tmx")))
    } else {
        Err(std::io::Error::new(std::io::ErrorKind::NotFound, "file not found"))
    }
}

} `` Check theResourceReader` docs for more information.

Licences

assets/tilesheet.png by Buch

Licenced under MIT