In the load_map function, we iterate over tilesets and layers to create both tiles and objects:
for (tileset_index, tileset) in tiled_map.map.tilesets().iter().enumerate() {
for (layer_index, layer) in tiled_map.map.layers().enumerate() {
match layer.layer_type() {
LayerType::Tiles(tile_layer) => {
// spawn tiles
LayerType::Objects(object_layer) => {
// spawn objects
}
}
This logic is needed for tiles since a TileLayer can contains tiles from multiple tilesets but with the current implementation, it leads to spawn every object once per tileset which is not what we want.
Solution would be to only iterate over the tileset for LayerType::Tiles layers:
for (layer_index, layer) in tiled_map.map.layers().enumerate() {
match layer.layer_type() {
LayerType::Tiles(tile_layer) => {
for (tileset_index, tileset) in tiled_map.map.tilesets().iter().enumerate() {
// spawn tiles
}
LayerType::Objects(object_layer) => {
// spawn objects
}
}
In the
load_map
function, we iterate over tilesets and layers to create both tiles and objects:This logic is needed for tiles since a
TileLayer
can contains tiles from multiple tilesets but with the current implementation, it leads to spawn every object once per tileset which is not what we want.Solution would be to only iterate over the tileset for
LayerType::Tiles
layers: