# How Can I Split Maps?

**URL:** <https://discourse.mapeditor.org/t/how-can-i-split-maps/5070>\
**Category:** Questions\
**Created:** [April 16, 2021, 9:42pm UTC](https://discourse.mapeditor.org/t/how-can-i-split-maps/5070 "2021-04-16T21:42:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FiveBrosStopMosYT](https://avatars.discourse-cdn.com/v4/letter/f/c6cbf5/32.png) [@FiveBrosStopMosYT](https://discourse.mapeditor.org/u/FiveBrosStopMosYT)\
**Post date:** [April 16, 2021, 9:42pm UTC](https://discourse.mapeditor.org/t/how-can-i-split-maps/5070/1 "2021-04-16T21:42:26Z")

</div>

So, I’m tiling the world for my game, and it got out of hand. I figured out how to use infinite worlds, but I want to be able to crop my map into chunks so that the game can load in only a small section of the world to prevent lag. Is there any way to do this?

---

<div class="post-metadata">

**Author:** ![eishiya](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/eishiya/32/2534_2.png) [@eishiya](https://discourse.mapeditor.org/u/eishiya)\
**Post date:** [April 17, 2021, 1:11pm UTC](https://discourse.mapeditor.org/t/how-can-i-split-maps/5070/2 "2021-04-17T13:11:45Z")

</div>

Infinite maps are already chunked, and you can control the size of the chunks in Map Properties.

When you load the map, don’t load the entire thing, load just the chunks you need, and stream in the rest as the player moves across the world. This way, only a few chunks of the world are loaded at any given time. The infinite map format was created specifically with data streaming in mind, I believe.

If you’re looking for a creation-time solution to split up the map into several separate maps with transitions between them: You can create a copy of the map, select the area you want to crop out, and `Map > Crop to Selection`. Rinse and repeat. If you’ve already made a lot, you can potentially automate this with scripting.  
However, this is not an ideal solution for the future. For your future mapping, I recommend creating your smaller maps right away instead of working in one giant map. You can still view them all together if you create a World and add them all to that world.

---

<div class="post-metadata">

**Author:** ![FiveBrosStopMosYT](https://avatars.discourse-cdn.com/v4/letter/f/c6cbf5/32.png) [@FiveBrosStopMosYT](https://discourse.mapeditor.org/u/FiveBrosStopMosYT)\
**Post date:** [April 17, 2021, 10:31pm UTC](https://discourse.mapeditor.org/t/how-can-i-split-maps/5070/3 "2021-04-17T22:31:17Z")

</div>

Ok, thanks for your help! 😃  
-Sincerely  
FiveBrosStopMosYT

---

<div class="post-metadata">

**Author:** ![bjorn](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/bjorn/32/1599_2.png) [@bjorn](https://discourse.mapeditor.org/u/bjorn)\
**Post date:** [April 19, 2021, 12:47pm UTC](https://discourse.mapeditor.org/t/how-can-i-split-maps/5070/5 "2021-04-19T12:47:35Z")

</div>

> [@eishiya](#):
>
> The infinite map format was created specifically with data streaming in mind, I believe.

I have to disappoint a little here, since all supported formats (JSON, TMX and Lua) that store chunks would anyway have to be fully parsed to get at any desired chunk (except TMX, would could be read up to that point, but that doesn’t help much).

Basically, the chunked format only avoids storing large empty areas, which makes a big difference especially when a lot of sparsely filled layers are used. It does also help with avoiding conflicts when multiple people edit the same world. But the file generally still needs to be entirely loaded.

So yeah, the two solutions here would be:

- Script a custom action to automate the cropping + saving sequence.
- Use the worlds feature instead, so you can edit multiple separate maps but still see them in a single view (though, if you’ve already got a very large map, you may want to look into scripting the above anyway, even if you only plan to do it once).

If you consider scripting this, here’s some lines to help you on your way:

```js
// Resize + offset the map to capture a chunk (passing `true` to also delete objects outside of the map)
tiled.activeAsset.resize(Qt.size(16, 16), Qt.point(-16, 0), true)

// Save the chunk in TMX format
tiled.mapFormat("tmx").write(tiled.activeAsset, "/tmp/test.tmx")

// Undo the resize (to perform a resize to the next chunk)
tiled.activeAsset.undo()

```

You’d need to perform the above in a loop. Note that since it relies on undo being available it would need to operate on a currently open map.

Also, for an infinite map there’s currently no way to directly get the bounds of the entire map. You can get the bounds of an individual tile layer by doing `tiled.activeAsset.layerAt(0).region().boundingRect`. In case of multiple tile layers you’d want to combine the regions (using `totalRegion.add(region)` before calling `boundingRect`.

---

<div class="post-metadata">

**Author:** ![FiveBrosStopMosYT](https://avatars.discourse-cdn.com/v4/letter/f/c6cbf5/32.png) [@FiveBrosStopMosYT](https://discourse.mapeditor.org/u/FiveBrosStopMosYT)\
**Post date:** [April 20, 2021, 2:47am UTC](https://discourse.mapeditor.org/t/how-can-i-split-maps/5070/6 "2021-04-20T02:47:02Z")

</div>

Ok, thanks. 😃
