TextureAtlas and produces a new TMX/TMJ file to be loaded with an
AtlasTiledMapLoader loader. Optionally, it can keep track of unused tiles and omit them from the generated atlas, reducing the
resource size.
The original TMX or TMJ map file will be parsed by using the TmxMapLoader or TmjMapLoader loader, thus access
to a valid OpenGL context is required, that's why an LwjglApplication is created by this preprocessor.
The new TMX/TMJ map file will contain a new property, named "atlas", whose value will enable the AtlasTiledMapLoader to
correctly read the associated TextureAtlas representing the tileset. The map file will also overwrite the sources of any
imagelayer images to a new unique region name prepending 'atlas_imagelayer_' to a newly generated one which represents it's
region in the atlas
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| private static class | |
| private static class | |
| private static class | TiledMapPacker.
Below we have 2 custom subclasses of the Map Loaders we use within the TiledMapPacker PackerTmxMapLoader and PackerTmjMapLoader. |
| public static class |
| Modifier and Type | Field and Description |
|---|---|
| private static String | |
| private FileHandle | |
| private ObjectMap | |
| private ObjectMap | |
| public static File | |
| private TiledMap | |
| private TiledMapPacker. | |
| public static File | |
| private TexturePacker | |
| public static String | |
| private TiledMapPacker. | |
| private static final String | |
| private ObjectMap | |
| private HashMap | |
| private com. | |
| private TiledMapPacker. | |
| private com. | |
| private static long |
| Access | Constructor and Description |
|---|---|
| public | |
| public | TiledMapPacker(TiledMapPacker.
Constructs a new preprocessor by using the specified packing settings |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private String | |
| private static Node | getFirstChildByNameAttrValue(Node node, String childName, String attr, String value)
If the child node or attribute doesn't exist, it is created. |
| private static Node | |
| private IntArray | Returns: a bucketThe size to use to create a new bucket if it doesn't exist, else specify 0 or lower to return null instead size)Returns the usedIds bucket for the given tileset name. |
| public static void | main(String[]
args[0]: the input directory containing the tmx/tmj files (and tile sets, and imagelayer imaged relative to the
path listed in the tmx file). args[1]: The output directory for the tmx/tmj files, should be empty before running.
args[2]: The location of the TiledMap Project File. args[2-5] options args)Processes a directory of Tile Maps, compressing each tile set contained in any map once. |
| private void | |
| private void | packImageLayerImages(FileHandle inputDirHandle)
Traverse the map of generated image names created from generateImageLayerImageNames() in imagesLayersToPack, get image
source path and pass image to the |
| private void | packSingleImageTileset(TiledMapTileSet set, FileHandle inputDirHandle)
Handles a tileset that uses one large image for all its tiles. |
| private void | packTilesets(FileHandle inputDirHandle, TexturePacker.
Traverse the specified tilesets, optionally lookup the used ids and pass every tile image to the |
| private static void | |
| private void | |
| private void | |
| public void | processInputDir(TexturePacker.
You can either run the |
| public void | processInputDir(TexturePacker.
the texturePackerSettings,Settings used for packing textures (e.g., padding, filtering, etc.)the path to the directory containing map files (.tmx or .tmj); must not be null or empty inputDirPath, String optional path where processed map files and the atlas will be written; if empty or null, defaults to
"../output/" relative to input outputDirPath, String optional path to a Tiled project file, used when maps require loading a custom tiled project file can be
left "" or null prjtFilePath)Processes a directory of Tiled .tmx or .tmj map files, optionally including subdirectories, and outputs updated map files and a texture atlas. |
| private void | |
| private void | |
| private void | processSubdirectories(FileHandle
The directory to look for maps and other directories currentDir, TexturePacker.Looks for subdirectories inside parentHandle, processes maps in subdirectory, repeat. |
| private void | processTmjImageLayersRecursively(JsonValue root)
Start processing at the top of the .tmj's "layers" array. |
| private void | processTmxImageLayersRecursively(Node parent)
Recursively searches for imagelayer nodes anywhere under the given 'parent'. |
| private String | removeExtensionIfPresent(String path)
Small helper for removing common image file extensions from the end. |
| private void | |
| private static void | |
| private void | |
| private void | |
| private String | |
| private void | |
| private void |
| AtlasOutputName | back to summary |
|---|---|
| private static String AtlasOutputName | |
| currentDir | back to summary |
|---|---|
| private FileHandle currentDir | |
| imageLayerSourceFiles | back to summary |
|---|---|
| private ObjectMap<String, String> imageLayerSourceFiles | |
| imagesLayersToPack | back to summary |
|---|---|
| private ObjectMap<String, Array<String>> imagesLayersToPack | |
| inputDir | back to summary |
|---|---|
| public static File inputDir | |
| map | back to summary |
|---|---|
| private TiledMap map | |
| mapLoader | back to summary |
|---|---|
| private TiledMapPacker. | |
| outputDir | back to summary |
|---|---|
| public static File outputDir | |
| packer | back to summary |
|---|---|
| private TexturePacker packer | |
| projectFilePath | back to summary |
|---|---|
| public static String projectFilePath | |
| settings | back to summary |
|---|---|
| private TiledMapPacker. | |
| TilesetsOutputDir | back to summary |
|---|---|
| private static final String TilesetsOutputDir | |
| tilesetsToPack | back to summary |
|---|---|
| private ObjectMap<String, TiledMapTileSet> tilesetsToPack | |
| tilesetUsedIds | back to summary |
|---|---|
| private HashMap<String, IntArray> tilesetUsedIds | |
| tmjLoaderParams | back to summary |
|---|---|
| private com. | |
| tmjMapLoader | back to summary |
|---|---|
| private TiledMapPacker. | |
| tmxLoaderParams | back to summary |
|---|---|
| private com. | |
| uniqueIdCounter | back to summary |
|---|---|
| private static long uniqueIdCounter | |
| TiledMapPacker | back to summary |
|---|---|
| public TiledMapPacker() Constructs a new preprocessor by using the default packing settings | |
| TiledMapPacker | back to summary |
|---|---|
| public TiledMapPacker(TiledMapPacker. Constructs a new preprocessor by using the specified packing settings | |
| addTile | back to summary |
|---|---|
| private void addTile(TiledMapTile tile, int bucketSize) | |
| generateUniqueImageName | back to summary |
|---|---|
| private String generateUniqueImageName(String imageSource) | |
| getFirstChildByNameAttrValue | back to summary |
|---|---|
| private static Node getFirstChildByNameAttrValue(Node node, String childName, String attr, String value) If the child node or attribute doesn't exist, it is created. Usage example: Node property = getFirstChildByAttrValue(properties, "property", "name"); | |
| getFirstChildNodeByName | back to summary |
|---|---|
| private static Node getFirstChildNodeByName(Node parent, String child) If the child node doesn't exist, it is created. | |
| getUsedIdsBucket | back to summary |
|---|---|
| private IntArray getUsedIdsBucket(String tilesetName, int size) Returns the usedIds bucket for the given tileset name. If it doesn't exist one will be created with the specified size if its > 0, else null will be returned.
| |
| main | back to summary |
|---|---|
| public static void main(String[] args) Processes a directory of Tile Maps, compressing each tile set contained in any map once.
| |
| packCollectionOfImagesTileset | back to summary |
|---|---|
| private void packCollectionOfImagesTileset(TiledMapTileSet set, FileHandle inputDirHandle) throws IOException | |
| packImageLayerImages | back to summary |
|---|---|
| private void packImageLayerImages(FileHandle inputDirHandle) throws IOException Traverse the map of generated image names created from generateImageLayerImageNames() in imagesLayersToPack, get image
source path and pass image to the | |
| packSingleImageTileset | back to summary |
|---|---|
| private void packSingleImageTileset(TiledMapTileSet set, FileHandle inputDirHandle) throws IOException Handles a tileset that uses one large image for all its tiles. | |
| packTilesets | back to summary |
|---|---|
| private void packTilesets(FileHandle inputDirHandle, TexturePacker. Traverse the specified tilesets, optionally lookup the used ids and pass every tile image to the | |
| printUsage | back to summary |
|---|---|
| private static void printUsage() | |
| processImageLayerNames | back to summary |
|---|---|
| private void processImageLayerNames(Node imagelayerNode) Here we Process a single | |
| processImageLayerNames | back to summary |
|---|---|
| private void processImageLayerNames(JsonValue imageLayer) | |
| processInputDir | back to summary |
|---|---|
| public void processInputDir(TexturePacker. You can either run the | |
| processInputDir | back to summary |
|---|---|
| public void processInputDir(TexturePacker. Processes a directory of Tiled .tmx or .tmj map files, optionally including subdirectories, and outputs updated map files
and a texture atlas. This method is intended for usage from external callers such as build scripts or other Java classes.
Keep in mind that this preprocessor will need to load the maps by using the
| |
| processLayerNode | back to summary |
|---|---|
| private void processLayerNode(JsonValue layerNode) Recursively process a tmj layer node | |
| processSingleMap | back to summary |
|---|---|
| private void processSingleMap(File mapFile, FileHandle dirHandle, TexturePacker. | |
| processSubdirectories | back to summary |
|---|---|
| private void processSubdirectories(FileHandle currentDir, TexturePacker. Looks for subdirectories inside parentHandle, processes maps in subdirectory, repeat.
| |
| processTmjImageLayersRecursively | back to summary |
|---|---|
| private void processTmjImageLayersRecursively(JsonValue root) Start processing at the top of the .tmj's "layers" array. | |
| processTmxImageLayersRecursively | back to summary |
|---|---|
| private void processTmxImageLayersRecursively(Node parent) Recursively searches for imagelayer nodes anywhere under the given 'parent'. If it finds any imagelayers, it updates the source attribute to a unique name, and tracks that in imagesLayersToPack/imageLayerSourceFiles. | |
| removeExtensionIfPresent | back to summary |
|---|---|
| private String removeExtensionIfPresent(String path) Small helper for removing common image file extensions from the end. | |
| savePacker | back to summary |
|---|---|
| private void savePacker() throws IOException | |
| setProperty | back to summary |
|---|---|
| private static void setProperty(Document doc, Node parent, String name, String value) | |
| setProperty | back to summary |
|---|---|
| private void setProperty(JsonValue root, String name, String value) | |
| stripUnusedTiles | back to summary |
|---|---|
| private void stripUnusedTiles() | |
| tilesetNameFromTileId | back to summary |
|---|---|
| private String tilesetNameFromTileId(TiledMap map, int tileid) | |
| writeUpdatedTMJ | back to summary |
|---|---|
| private void writeUpdatedTMJ(FileHandle tmjFileHandle) throws IOException | |
| writeUpdatedTMX | back to summary |
|---|---|
| private void writeUpdatedTMX(FileHandle tmxFileHandle) throws IOException | |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | accept(File f, String s)
Implements java. Tests if a specified file should be included in a file list. |
| DirFilter | back to summary |
|---|---|
| public DirFilter() | |
| accept | back to summary |
|---|---|
| public boolean accept(File f, String s) Implements java. Doc from java. Tests if a specified file should be included in a file list.
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | accept(File dir, String name)
Implements java. Tests if a specified file should be included in a file list. |
| MapFileFilter | back to summary |
|---|---|
| public MapFileFilter() | |
| accept | back to summary |
|---|---|
| public boolean accept(File dir, String name) Implements java. Doc from java. Tests if a specified file should be included in a file list.
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected void | addStaticTiles(FileHandle tmjFile, ImageResolver imageResolver, TiledMapTileSet tileSet, JsonValue element, JsonValue tiles, String name, int firstgid, int tilewidth, int tileheight, int spacing, int margin, int offsetX, int offsetY, String imageSource, int imageWidth, int imageHeight, FileHandle image)
Overrides com.
|
| protected AnimatedTiledMapTile | createAnimatedTile(TiledMapTileSet tileSet, TiledMapTile originalTile, JsonValue tileDefinition, int firstgid)
Overrides com.
|
| PackerTmjMapLoader | back to summary |
|---|---|
| public PackerTmjMapLoader(FileHandleResolver resolver) | |
| addStaticTiles | back to summary |
|---|---|
| protected void addStaticTiles(FileHandle tmjFile, ImageResolver imageResolver, TiledMapTileSet tileSet, JsonValue element, JsonValue tiles, String name, int firstgid, int tilewidth, int tileheight, int spacing, int margin, int offsetX, int offsetY, String imageSource, int imageWidth, int imageHeight, FileHandle image) Overrides com.
| |
| createAnimatedTile | back to summary |
|---|---|
| protected AnimatedTiledMapTile createAnimatedTile(TiledMapTileSet tileSet, TiledMapTile originalTile, JsonValue tileDefinition, int firstgid) Overrides com.
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected void | addStaticTiles(FileHandle tmxFile, ImageResolver imageResolver, TiledMapTileSet tileSet, XmlReader.
Overrides com.
|
| protected AnimatedTiledMapTile | createAnimatedTile(TiledMapTileSet tileSet, TiledMapTile originalTile, XmlReader.
Overrides com.
|
| PackerTmxMapLoader | back to summary |
|---|---|
| public PackerTmxMapLoader(FileHandleResolver resolver) | |
| addStaticTiles | back to summary |
|---|---|
| protected void addStaticTiles(FileHandle tmxFile, ImageResolver imageResolver, TiledMapTileSet tileSet, XmlReader. Overrides com.
| |
| createAnimatedTile | back to summary |
|---|---|
| protected AnimatedTiledMapTile createAnimatedTile(TiledMapTileSet tileSet, TiledMapTile originalTile, XmlReader. Overrides com.
| |
| Modifier and Type | Field and Description |
|---|---|
| public String | |
| public boolean | |
| public boolean | |
| public boolean | |
| public String | |
| public boolean |
| Access | Constructor and Description |
|---|---|
| public |
| atlasOutputName | back to summary |
|---|---|
| public String atlasOutputName | |
| combineTilesets | back to summary |
|---|---|
| public boolean combineTilesets | |
| ignoreCollectionOfImages | back to summary |
|---|---|
| public boolean ignoreCollectionOfImages | |
| stripUnusedTiles | back to summary |
|---|---|
| public boolean stripUnusedTiles | |
| tilesetOutputDirectory | back to summary |
|---|---|
| public String tilesetOutputDirectory | |
| verbose | back to summary |
|---|---|
| public boolean verbose | |
| TiledMapPackerSettings | back to summary |
|---|---|
| public TiledMapPackerSettings() | |