Skip to content

Commit 5870bdf

Browse files
authored
Added brand new wiki page for the newly updated TiledMapPacker tool. (#244)
Added new wiki page for the TiledMapPacker tool. As well as modified sections of the site where it would be included near the other gdx-tools. Updated tile-maps.md to reference this new wiki documentation.
1 parent 56bbdb7 commit 5870bdf

File tree

9 files changed

+152
-0
lines changed

9 files changed

+152
-0
lines changed

_includes/wiki_index.md

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
* [Overlap2D](/wiki/tools/overlap2d)
122122
* [Skin Composer](/wiki/tools/skin-composer)
123123
* [Texture packer](/wiki/tools/texture-packer)
124+
* [Tiled Map Packer](/wiki/tools/tiled-map-packer)
124125
* Utilities
125126
* [Collections](/wiki/utils/collections)
126127
* [jnigen](/wiki/utils/jnigen)

_includes/wiki_sidebar.md

+1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
* [Overlap2D](/wiki/tools/overlap2d)
183183
* [Skin Composer](/wiki/tools/skin-composer)
184184
* [Texture packer](/wiki/tools/texture-packer)
185+
* [Tiled Map Packer](/wiki/tools/tiled-map-packer)
185186
</div>
186187
</details>
187188

_pages/dev/tools.md

+6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ feature_row4:
8383
url: "/wiki/tools/texture-packer"
8484
btn_label: "Documentation & Download"
8585
btn_class: "btn--primary"
86+
- image_path: /assets/images/dev/tools/tiled_map_packer.gif
87+
title: "Tiled Map Packer"
88+
excerpt: 'A tool for packing TiledMap tilesets into an atlas'
89+
url: "/wiki/tools/tiled-map-packer"
90+
btn_label: "Documentation & Download"
91+
btn_class: "btn--primary"
8692

8793
sidebar:
8894
nav: "dev"
213 KB
Loading
467 KB
Loading
2.04 MB
Loading
2.04 MB
Loading

wiki/graphics/2d/tile-maps.md

+11
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,17 @@ Once loaded you can treat the map just like an other TiledMap.
261261
*Note* if you want to use TMX maps with the GWT backend, you need to make sure the map is saved with pure base64 encoding. The compressed TMX formats will not work due to limitations in GWT.
262262
*Note* libGDX does not support infinite size for TMX maps (see [#5764](https://github.com/libgdx/libgdx/issues/5764)). Use only size-limited TMX maps.
263263

264+
### Loading TiledMapPacker Atlas TMX/TMJ Tiled maps
265+
The libGDX TiledMapPacker and AtlasTmxMapLoader have been around for years, but with recent updates it's been expanded to include
266+
more feature's and well as better documentation on how to use it.
267+
268+
Maps processed by TiledMapPacker must be loaded using the AtlasTmxMapLoader or AtlasTmjMapLoader classes instead of the standard map loaders.
269+
These specialized loaders recognize the extra atlas property embedded in the map file, ensuring tilesets, image layers, and collection-of-images tilesets are properly loaded from the generated TextureAtlas.
270+
271+
Using these loaders reduces draw calls, minimizes texture binds, and improves rendering efficiency. Especially for maps which heavily rely on image layers and multiple tilesets.
272+
273+
See the full [TiledMapPacker documentation](/wiki/tools/tiled-map-packer) for usage instructions.
274+
264275
### Loading Tide maps
265276
![images/tile-maps3.png](/assets/wiki/images/tile-maps3.png)
266277

wiki/tools/tiled-map-packer.md

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
---
2+
title: "Tiled Map Packer"
3+
---
4+
5+
# TiledMapPacker
6+
7+
> **Warning**, while the latest TiledMapPacker is available for download.
8+
> In order to use maps created with it. You must be using the latest SNAPSHOT version of libGDX, currently *1.13.2-SNAPSHOT*.
9+
10+
You can download the runnable JAR release of **TiledMapPacker**, [here](https://libgdx-nightlies.s3.eu-central-1.amazonaws.com/libgdx-runnables/runnable-tiledmappacker.jar).
11+
12+
*Offline tool for processing one or more Tiled maps (`.tmx` or `.tmj`) into a single optimized `TextureAtlas`, combining tilesets,
13+
image layers, and individual images into an atlas for use with the `AtlasTmxMapLoader` or `AtlasTmjMapLoader`.*
14+
15+
16+
## Why use TiledMapPacker?
17+
18+
TiledMapPacker is designed to optimize your Tiled maps for better runtime performance:
19+
20+
- **Fewer draw calls** – By combining multiple tilesets, images, and layers into a single optimized `TextureAtlas`,
21+
your game can render entire maps faster with fewer texture switches. This is especially helpful for parallax backgrounds made using imagelayers, and maps that use a variety of tilesets.
22+
- **Optional tile stripping** – Unused tiles can be omitted to reduce file size and memory use.
23+
24+
25+
## Running TiledMapPacker
26+
27+
### Stand‑alone JAR
28+
29+
```
30+
# Creates an output directory named "output" next to INPUTDIR
31+
java -jar runnable-tiledmappacker.jar ./maps
32+
33+
# Explicit output directory
34+
java -jar runnable-tiledmappacker.jar ./maps ./maps-packed
35+
36+
# Explicit output directory, as well maps needing .tiled-project files to load
37+
java -jar runnable-tiledmappacker.jar ./maps ./maps-packed ./customClass.tiled-project
38+
39+
# Various options are available as well such as verbose logging and stripping unused tiles
40+
java -jar runnable-tiledmappacker.jar ./maps ./maps-packed -v --strip-unused`
41+
```
42+
43+
> **Note:** TiledMapPacker internally uses `TmxMapLoader` and `TmjMapLoader`, which require a valid OpenGL context. The runnable JAR automatically creates a minimal LwjglApplication that opens a small window.
44+
45+
46+
## Positional arguments
47+
48+
| Argument | Description |
49+
|------------------- |-------------|
50+
| **INPUTDIR** | Folder that contains the maps. Searches recursively for `.tmx` and `.tmj` files.|
51+
| **OUTPUTDIR** | *(optional)* Directory where the processed maps and atlases are written. Defaults to a sibling directory named **output**.|
52+
| **PROJECTFILEPATH** | *(optional)* Path to a Tiled `.tiled-project` file when your maps rely on *custom classes*.|
53+
54+
## Flags
55+
56+
| Flag | Effect |
57+
| -------------------- |-------------------------------------------------------------------------------|
58+
| `--strip-unused` | Omit tiles that never appear in any layer. |
59+
| `--combine-tilesets` | Combine all tilesets from all maps into a single mega‑atlas (not recommended). |
60+
| `--ignore-coi` | Skip "*collection‑of‑images*" tilesets. |
61+
| `-v` | Verbose output (lists every tile or image that is packed/stripped). |
62+
63+
64+
## Default Per‑Map Atlases vs Combined
65+
66+
- **Per‑map** (default) – Each individual map gets its own atlas.
67+
68+
*Command*: `java -jar tiledmappacker.jar ./maps`.
69+
70+
- **Combined** – All tilesets across every map are packed into a single giant
71+
atlas, so you only need one atlas for all maps. This option has been around since the inception of the TiledMapPacker but still *not recommended* for use as nested folders and absolute tileset paths may break it.
72+
73+
*Option*: `--combine-tilesets`.
74+
75+
76+
## Typical Workflow
77+
78+
1. Design your map(s) in Tiled as usual.
79+
2. Run **TiledMapPacker** whenever your art or map files change.
80+
3. The packer creates updated map files (`.tmx` or `.tmj`) and a `tileset/` directory containing the generated `.atlas` and images.
81+
4. Make sure you keep your original tileset definitions (`.tsx` or `.tsj`) and place them alongside the newly generated map and atlas files.
82+
5. Then load the map exactly as you would a regular map:
83+
```java
84+
TiledMap map = new AtlasTmxMapLoader().load("maps/testLevel.tmx");
85+
```
86+
Or through the AssetManager class as well, like any other map.
87+
```java
88+
assetManager.setLoader(TiledMap.class, new AtlasTmxMapLoader(new InternalFileHandleResolver()));
89+
assetManager.load("maps/testLevel.tmx", TiledMap.class);
90+
```
91+
92+
93+
## Handling ImageLayers
94+
95+
Image‑layers are detected automatically. Each image is renamed to a safe region
96+
ID (prefixed with `atlas_imagelayer_`), packed into the atlas, and the map file
97+
is rewritten. The modified atlas map loaders resolve these names automatically.
98+
99+
100+
## Limitations
101+
102+
- **XML tile‑layer encoding** is not supported – stick to CSV or Base64 layers.
103+
- Having a `.tmx` *and* `.tmj` with the **same basename** in the same folder
104+
(e.g. `level1.tmx` and `level1.tmj`) will cause region‑name collisions and the
105+
packer will abort.
106+
- **Collection‑of‑images** tilesets are packed automatically, but if they are
107+
not used in tile layers and not meant to be rendered you can exclude them with `--ignore-coi`.
108+
- `--combine-tilesets` is experimental. Complex folder hierarchies or absolute
109+
tileset paths may fail to resolve correctly.
110+
111+
## Results
112+
113+
In a worse case scenario we have below a map created with 3 different tilesets, one of those tilesets being a
114+
"collection-of-images". As well as 8 image layers being used to for parallax background effects.
115+
116+
![TiledMap UI Layers](/assets/wiki/images/tiledmappacker1.png)
117+
118+
You can see the amount of draw calls being wasted if this map were loaded through the `TmxMapLoader`.
119+
In the below example we range 12 to 14 depending on where we are on the screen.
120+
121+
![Unoptimized TMX Map](/assets/wiki/images/tiledmappacker2.gif)
122+
123+
But choosing to use the TiledMapPacker and an `AtlasTmxMapLoader`. We can significantly reduce our draw calls.
124+
In this case, down to 1.
125+
126+
![Optimized Atlas TMX Map](/assets/wiki/images/tiledmappacker3.gif)
127+
128+
129+
130+
## Example Tests
131+
* [Running TiledMapPacker](https://github.com/libgdx/libgdx/blob/master/extensions/gdx-tools/src/com/badlogic/gdx/tiledmappacker/TiledMapPackerTest.java)
132+
* [Rendering Packed Atlas Tiled Maps](https://github.com/libgdx/libgdx/blob/master/extensions/gdx-tools/src/com/badlogic/gdx/tiledmappacker/TiledMapPackerTestRender.java)
133+

0 commit comments

Comments
 (0)