public final class TiledReader
extends java.lang.Object
The TiledReader class is the main class of the TiledReader library, and the library's means of accessing Tiled files. The TiledReader class cannot be instantiated; instead, it has static methods that read Tiled maps, tilesets, and object templates from specified files.
The TiledReader class stores pointers to the maps, tilesets, and object templates corresponding to all of the files it has read, and will use these pointers to return the very same resource object if asked to read the same file multiple times. This is mainly to ensure that, if multiple Tiled maps reference the same external tileset or object template file, the external file will not be wastefully parsed and stored in memory multiple times. However, the TiledReader class also contains static methods that can be called manually to remove these pointers. Removing the pointer to a no-longer-needed resource object is necessary to make the object vulnerable to the Java garbage collector.
TiledReader does not support image data embedded directly in TMX/TSX files. As of Tiled version 1.4.0, however, it is not possible to embed image data in files using the Tiled editor.
TiledReader also ignores information in Tiled files pertaining to deprecated or unsupported features of Tiled. These include the x and y attributes of tile layers, object layers, and image layers (not to be confused with the rendering x and y offsets, which are supported), as well as the width and height attributes of object layers.
For details on the structure and content of Tiled files, see the official Tiled documentation on the subject.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
TILED_VERSION
The version number of Tiled that this version of TiledReader was designed
for.
|
static java.lang.String |
TMX_VERSION
The version of the TMX file format that this version of TiledReader was
designed for.
|
static java.lang.String |
VERSION
The version number of TiledReader.
|
Modifier and Type | Method and Description |
---|---|
static void |
clearResources()
Removes all of the TiledReader class' pointers to resources that it has
read from files.
|
static TiledMap |
getMap(java.lang.String path)
Reads a Tiled map from the specified TMX file and returns it as a
TiledMap object.
|
static TiledObjectTemplate |
getTemplate(java.lang.String path)
Reads a Tiled object template from the specified TX file and returns it
as a TiledObjectTemplate object.
|
static TiledTileset |
getTileset(java.lang.String path)
Reads a Tiled tileset from the specified TSX file and returns it as a
TiledTileset object.
|
static boolean |
removeResource(java.lang.String path,
boolean cleanUp)
Removes the TiledReader class' pointer to the resource it read from the
specified file, if it has read that file before.
|
public static final java.lang.String VERSION
public static final java.lang.String TILED_VERSION
public static final java.lang.String TMX_VERSION
public static TiledMap getMap(java.lang.String path)
path
- The path to the TMX file to readpublic static TiledTileset getTileset(java.lang.String path)
path
- The path to the TSX file to readpublic static TiledObjectTemplate getTemplate(java.lang.String path)
path
- The path to the TX file to readpublic static boolean removeResource(java.lang.String path, boolean cleanUp)
path
- The path to the file to forget aboutcleanUp
- If true, also remove the pointers to all of the resources
referenced by the resource from the specified file, and not referenced by
any of the other resources that the TiledReader class still points to.
This parameter applies recursively, so if the removal of any of these
"orphaned" resources causes more resources to be orphaned, those will be
removed as well.public static void clearResources()