public final class TiledConverter
extends java.lang.Object
The TiledConverter class, along with the TiledArea class, allow Cell2D games to incorporate information from files created with the map editor Tiled. They accomplish this by interfacing with the TiledReader library, which is a dependency of Cell2D. The TiledConverter class cannot be instantiated; instead, it contains static methods for converting data structures from the TiledReader library into data structures native to Cell2D.
The TiledConverter class stores pointers to the Sprites and Animations corresponding to the TiledTilesets it has converted, as well as to the TiledAreas corresponding to the TiledMaps they have been constructed from. The TiledConverter class will use these pointers to return the very same Sprites and Animations if asked to convert the same TiledTileset multiple times. This is mainly to ensure that, if multiple TiledMaps reference the same TiledTileset, the TiledTileset will not be wastefully converted and stored in memory multiple times. However, the TiledConverter class also contains static methods that can be called manually to remove these pointers. Removing the pointers to no-longer-needed Sprites, Animations, and TiledAreas is necessary to make those objects vulnerable to the Java garbage collector. (Keep in mind, however, that unloading the Sprites is also necessary to fully free the memory they take up.)
Tiled stores the durations of tile animation frames in milliseconds, but Cell2D stores the durations of Animation frames in fracunits. The TiledConverter class converts milliseconds to fracunits using a consistent rate, which by default is one fracunit for every 16 milliseconds. The TiledConverter also contains static methods for getting and setting this conversion rate.
TiledArea
Modifier and Type | Method and Description |
---|---|
static void |
clearAssets()
Removes all of the TiledConverter class' pointers to the assets that have
been converted from Tiled resources.
|
static Animatable |
getAnimatable(org.tiledreader.TiledTile tile,
java.util.Set<Filter> filters,
boolean load)
Converts the TiledTileset to which the specified TiledTile belongs, if it
has not already been converted, and returns the Animatable representation
of the specified TiledTile.
|
static long |
getFracunitsPerMS()
Returns the TiledConverter class' milliseconds-to-fracunits conversion
rate, in fracunits per millisecond.
|
static java.lang.Iterable<Sprite> |
getSprites(org.tiledreader.TiledTileset tileset,
java.util.Set<Filter> filters,
boolean load)
Converts the specified TiledTileset, if it has not already been
converted, and returns an Iterable of the Sprites corresponding to all of
the TiledTileset's TiledTiles.
|
static boolean |
removeAssets(org.tiledreader.TiledResource resource,
boolean cleanUp,
boolean removeResources)
Removes the TiledConverter class' pointer to the assets converted from
the specified resource, if it has been converted before.
|
static void |
setFracunitsPerMS(long fracunitsPerMS)
Sets the TiledConverter class' milliseconds-to-fracunits conversion rate
to the specified value.
|
public static long getFracunitsPerMS()
public static void setFracunitsPerMS(long fracunitsPerMS)
fracunitsPerMS
- The new conversion rate, in fracunits per
millisecondpublic static java.lang.Iterable<Sprite> getSprites(org.tiledreader.TiledTileset tileset, java.util.Set<Filter> filters, boolean load)
tileset
- The TiledTileset whose corresponding Sprites are to be
returnedfilters
- If the TiledTileset has not yet been converted, this
parameter determines the Set of Filters that should have an effect on the
TiledTileset's Sprites when applied to them with draw(). If this is null,
no Filters will have an effect.load
- If this is true, all of the TiledTileset's Sprites (that are
not already loaded) will be loaded before this method returns.public static Animatable getAnimatable(org.tiledreader.TiledTile tile, java.util.Set<Filter> filters, boolean load)
tile
- The TiledTile for which the representative Animatable is to
be returnedfilters
- If the TiledTile's TiledTileset has not yet been
converted, this parameter determines the Set of Filters that should have
an effect on the TiledTileset's Sprites when applied to them with draw().
If this is null, no Filters will have an effect.load
- If this is true, all of the TiledTileset's Sprites (that are
not already loaded) will be loaded before this method returns.public static boolean removeAssets(org.tiledreader.TiledResource resource, boolean cleanUp, boolean removeResources)
resource
- The resource to forget aboutcleanUp
- If true, also remove the pointers to all of the assets
referenced by the assets from the specified resource, and not referenced
by any of the other assets that the TiledConverter class still points to.
This parameter applies recursively, so if the removal of any of these
"orphaned" assets causes more assets to be orphaned, those will be
removed as well.removeResources
- If true, also remove the TiledReader class'
pointer to the specified resource, if that pointer exists. Note that the
removal is based on the resource's source path rather than its identity
as an Object, and so if the resource from that same path has already been
removed from and re-read by the TiledReader class, the TiledReader class
will remove its pointer to the new resource. The cleanUp parameter
applies here as well; if it is true, the TiledReader class will also
clean up its orphaned resources.public static void clearAssets()