Expand description
A handy crate for parsing the Tiled JSON data in to a usable structure.
The crate includes a few small helper functions on Map
, TileSet
, and
TileLayer
. These functions are for common tasks such as generating a
cloumn/row location (tiles are stored in a 1D array), a located box on an
image for helping with tile-to-tilesheet image picking, and loading files
(or strings).
§Examples
use tiled_json_rs as tiled;
let map = tiled::Map::load_from_file(&PathBuf::from("tests/data/csv.json"))
.expect("Failed to load map");
for tileset in &map.tile_sets {
let name = tileset.name.clone();
let mut path = PathBuf::from("assets");
path.push(tileset.image.clone());
// Do stuff
}
use tiled::Layer;
fn render_layers(layers: &Vec<Layer>) {
for layer in layers {
match &layer.layer_type {
tiled::LayerType::TileLayer(tiles) => {
//do_something(tiles);
}
tiled::LayerType::Group { layers } => {
&mut render_layers(layers);
}
tiled::LayerType::ImageLayer(image) => {
//do_something_else(image);
}
tiled::LayerType::ObjectGroup(objects) => {
//and_another_thing(objects);
}
}
}
}
render_layers(&map.layers);
§Info
Tiled can export maps as JSON files. To do so, simply select “File > Export As”
and select the JSON file type. You can export json from the command line with
the --export-map
option.
Notes:
- GID for tiles starts at 1 with 0 reserved for empty tile
- Local Id starts at 0 for
TileSet
, and only applies toTileSet
- Doc comments are only provided where clarification may be useful. In general things should be named well enough that intention is self-describing.
Structs§
- Chunk
- Chunks are used to store the tile layer data for infinite maps
- Color
- An RGBA representation of colours
- Frame
- Data for an individual frame of animation
- Group
- Used to group layers if required
- Image
Layer - Contains a file path to an image plus a mix colour
- Layer
- A map can contain any number of layers.
- Map
- The base structure which contains all data - as in the root of a tree
- Object
- Object
Group - Terrain
- Text
- Tile
- Contains all possible data for a tile including an optional
ObjectGroup
- Tile
Layer - Tile
Rect - Used to provide the location and dimensions of the required tile on the tiles tileset image.
- TileSet
- A tileset that associates information with each tile.
- Vec2
- A simple representation of a 2d Vector to pass coords around
- Wang
Color - WangSet
- Data set for
Wang
tiles - Wang
Tile
Enums§
- Draw
Order - Can be
TopDown
(default) orIndex
. Applies toObjectGroup
only. - Layer
Type - Contains the data for this variant of layer
- Object
Type - Contains data for the object sub-types
- Orientation
- The orientation of the
Map
- Render
Order - Rendering direction. Applies only to orthogonal maps
- Stagger
Axis - Applies only to staggered or hexagonal maps
- Stagger
Index - Applies only to staggered or hexagonal maps
- Tiled
Value - A
TiledValue
is similar to JSON values.