T
- The type of CellGame that uses the SpaceStates that can load this
TiledAreaU
- The type of SpaceState that can load this TiledAreapublic abstract class TiledArea<T extends CellGame,U extends SpaceState<T,U,?>> extends java.lang.Object implements Area<T,U>
The TiledArea class, along with the TiledConverter 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. An instance of the TiledArea class is a type of Area that represents the contents of a TiledMap.
A TiledArea has an associated TiledConverter, specified upon its construction. This TiledConverter's associated TiledReader must be the same one that read the TiledArea's TiledMap. Constructing a TiledArea constitutes "converting" its TiledMap in the view of its TiledConverter, and the TiledConverter thus stores a pointer to the newly constructed TiledArea. The new TiledArea will replace the TiledConverter's pointer to any previous TiledArea constructed from the same TiledMap.
When a TiledArea is constructed, it will cause all of the TiledTilesets used in its TiledMap to be converted by its TiledCoverter if they have not been already. The TiledArea will also construct Sprites that display the images of the TiledMap's TiledImageLayers. (TiledImageLayers with identical images will share a single Sprite.) Any new Sprites converted or constructed upon a TiledArea's creation will not be affected by any Filters applied to them with draw().
The default implementation of a TiledArea's load() method translates its TiledMap's non-group layers one by one into sets of SpaceObjects. As part of this process, it calls three other methods: loadTileLayer(), loadObjectLayer(), and loadImageLayer(), for loading each TiledTileLayer, TiledObjectLayer, and TiledImageLayer, respectively. loadTileLayer() and loadImageLayer() have default implementations, but can be overridden. Currently, these default implementations assume that the TiledMap's orientation is orthogonal and ignore its within-tile-layer rendering order. loadObjectLayer() has no default implementation, because no such implementation could account for the diversity of custom SpaceObject subclasses that Cell2D games may use. Each non-group layer is translated with a particular draw priority, which is intended to be (and by default is) the draw priority of the SpaceObjects generated from it.
A TiledArea stores a list of Loadables used by its content, including the Sprites corresponding to TiledTiles and TiledImageLayers. These Loadables can be manually loaded and unloaded in bulk, and any unloaded ones will be automatically loaded by the TiledArea's load() method.
TiledConverter
Constructor and Description |
---|
TiledArea(org.tiledreader.TiledMap map,
TiledConverter converter,
int[] drawPriorities,
java.lang.String solidLayerName,
int backgroundColorLayerID,
boolean load)
Constructs a TiledArea that represents the contents of the specified
TiledMap.
|
TiledArea(org.tiledreader.TiledMap map,
TiledConverter converter,
int drawPrioritySpacing,
java.lang.String zeroPriorityLayerName,
java.lang.String solidLayerName,
int backgroundColorLayerID,
boolean load)
Constructs a TiledArea that represents the contents of the specified
TiledMap.
|
Modifier and Type | Method and Description |
---|---|
int |
getBackgroundColorLayerID()
Returns the integer ID with which this TiledArea's background color
SpaceLayer is assigned to the SpaceStates that load it.
|
TiledConverter |
getConverter()
Returns this TiledArea's associated TiledConverter.
|
int |
getLayerDrawPriority(int index)
Returns the draw priority of the non-group layer at the specified index
in this TiledArea's TiledMap's list of non-group layers (accessed via
getNonGroupLayers()).
|
java.util.List<Loadable> |
getLoadables()
Returns an unmodifiable List view of this TiledArea's stored Loadables.
|
org.tiledreader.TiledMap |
getMap()
Returns the TiledMap whose contents this TiledArea represents.
|
org.tiledreader.TiledTileLayer |
getSolidLayer()
Returns the TiledTileLayer that this TiledArea makes solid via the
default implementation of loadTileLayer(), or null if there is no such
TiledTileLayer.
|
Sprite |
getSprite(org.tiledreader.TiledImageLayer layer)
Returns the Sprite that this TiledArea constructed to represent the
specified TiledImageLayer, or null if the TiledImageLayer is not part of
this TiledArea's TiledMap.
|
static Color |
getTintColor(org.tiledreader.TiledLayer layer)
Returns a Cell2D Color that represents the tint color of the specified
TiledLayer.
|
static Color |
getTransColor(org.tiledreader.TiledImage image)
Returns the transparent color of the specified TiledImage as a Cell2D
Color, or null if the TiledImage does not have a transparent color.
|
java.lang.Iterable<SpaceObject> |
load(T game,
U state)
Actions for this Area to take to in order for the specified SpaceState to
load it.
|
java.lang.Iterable<SpaceObject> |
loadImageLayer(T game,
U state,
org.tiledreader.TiledImageLayer layer,
int drawPriority)
Generates a set of SpaceObjects to represent the specified
TiledImageLayer.
|
void |
loadLoadables()
Loads all of this TiledArea's stored Loadables (that are not already
loaded).
|
abstract java.lang.Iterable<SpaceObject> |
loadObjectLayer(T game,
U state,
org.tiledreader.TiledObjectLayer layer,
int drawPriority)
Generates a set of SpaceObjects to represent the specified
TiledObjectLayer.
|
java.lang.Iterable<SpaceObject> |
loadTileLayer(T game,
U state,
org.tiledreader.TiledTileLayer layer,
int drawPriority)
Generates a set of SpaceObjects to represent the specified
TiledTileLayer.
|
void |
unloadLoadables()
Unloads all of this TiledArea's stored Loadables that are currently
loaded.
|
public TiledArea(org.tiledreader.TiledMap map, TiledConverter converter, int drawPrioritySpacing, java.lang.String zeroPriorityLayerName, java.lang.String solidLayerName, int backgroundColorLayerID, boolean load)
map
- The TiledMap to construct the TiledArea fromconverter
- The TiledArea's associated TiledConverterdrawPrioritySpacing
- The difference in the draw priorities of
successive non-group layers. For instance, if this is set to 100, then if
one non-group layer has draw priority 0, the next frontmost non-group
layer will have draw priority 100, and the next frontmost non-group layer
after that will have draw priority 200, etc.zeroPriorityLayerName
- The name (accessed via getName()) of the
non-group layer with draw priority 0. This parameter may be null. If no
non-group layer has this parameter as a name, the first non-group layer
will have draw priority 0. If multiple non-group layers have this
parameter as a name, the hindmost one will have draw priority 0.solidLayerName
- The name (accessed via getName()) of the TiledTileLayer whose tiles will be overlaid with solid SpaceObjects by the default implementation of loadTileLayer(). This layer can be a visible layer that depicts a part of the game world, or it can be an invisible "solidity layer" whose only purpose is to specify collision information. loadTileLayer() will use the output of TileGridObject.cover() to generate a small set of solid, invisible, rectangular SpaceObjects that overlap all and only the grid locations in the TiledTileLayer that are occupied by tiles.
This parameter may be null. If no TiledTileLayer has this parameter as a name, none of the TiledTileLayers will be made solid. If multiple TiledTileLayers have this parameter as a name, only the hindmost one will be made solid.
backgroundColorLayerID
- If the TiledMap has a background color, the
default implementation of load() will assign a ColorSpaceLayer displaying
the background color to the loading SpaceState. This parameter is the
integer ID with which the ColorSpaceLayer is assigned to the SpaceState.
This parameter can be any number except 0, although if it is positive,
the "background" color will appear in the foreground.load
- If this is true, all of this TiledArea's Loadables (that are
not already loaded) will be loaded upon the TiledArea's creation.public TiledArea(org.tiledreader.TiledMap map, TiledConverter converter, int[] drawPriorities, java.lang.String solidLayerName, int backgroundColorLayerID, boolean load)
map
- The TiledMap to construct the TiledArea fromconverter
- The TiledArea's associated TiledConverterdrawPriorities
- An array whose length is the same as the number of
non-group layers in the TiledMap. The array element at each index
i will be the draw priority of the non-group layer at index i
in the TiledMap's list of non-group layers (accessed via
getNonGroupLayers()).solidLayerName
- The name (accessed via getName()) of the TiledTileLayer whose tiles will be overlaid with solid SpaceObjects by the default implementation of loadTileLayer(). This layer can be a visible layer that depicts a part of the game world, or it can be an invisible "solidity layer" whose only purpose is to specify collision information. loadTileLayer() will use the output of TileGridObject.cover() to generate a small set of solid, invisible, rectangular SpaceObjects that overlap all and only the grid locations in the TiledTileLayer that are occupied by tiles.
This parameter may be null. If no TiledTileLayer has this parameter as a name, none of the TiledTileLayers will be made solid. If multiple TiledTileLayers have this parameter as a name, only the hindmost one will be made solid.
backgroundColorLayerID
- If the TiledMap has a background color, the
default implementation of load() will assign a ColorSpaceLayer displaying
the background color to the loading SpaceState. This parameter is the
integer ID with which the ColorSpaceLayer is assigned to the SpaceState.
This parameter can be any number except 0, although if it is positive,
the "background" color will appear in the foreground.load
- If this is true, all of this TiledArea's Loadables (that are
not already loaded) will be loaded upon the TiledArea's creation.public static Color getTransColor(org.tiledreader.TiledImage image)
image
- The TiledImagepublic static Color getTintColor(org.tiledreader.TiledLayer layer)
layer
- The TiledLayerpublic java.lang.Iterable<SpaceObject> load(T game, U state)
Area
public java.lang.Iterable<SpaceObject> loadTileLayer(T game, U state, org.tiledreader.TiledTileLayer layer, int drawPriority)
game
- The CellGame of the SpaceState that is loading this TiledAreastate
- The SpaceState that is loading this TiledArealayer
- The TiledTileLayer to representdrawPriority
- The draw priority that the generated SpaceObjects
should havepublic abstract java.lang.Iterable<SpaceObject> loadObjectLayer(T game, U state, org.tiledreader.TiledObjectLayer layer, int drawPriority)
game
- The CellGame of the SpaceState that is loading this TiledAreastate
- The SpaceState that is loading this TiledArealayer
- The TiledObjectLayer to representdrawPriority
- The draw priority that the generated SpaceObjects
should havepublic java.lang.Iterable<SpaceObject> loadImageLayer(T game, U state, org.tiledreader.TiledImageLayer layer, int drawPriority)
game
- The CellGame of the SpaceState that is loading this TiledAreastate
- The SpaceState that is loading this TiledArealayer
- The TiledImageLayer to representdrawPriority
- The draw priority that the generated SpaceObjects
should havepublic final org.tiledreader.TiledMap getMap()
public final TiledConverter getConverter()
public final int getLayerDrawPriority(int index)
index
- The index of the non-group layer whose draw priority is to
be returnedjava.lang.IndexOutOfBoundsException
- if the index is out of rangepublic final org.tiledreader.TiledTileLayer getSolidLayer()
public final int getBackgroundColorLayerID()
public final java.util.List<Loadable> getLoadables()
public final void loadLoadables()
public final void unloadLoadables()
public final Sprite getSprite(org.tiledreader.TiledImageLayer layer)
layer
- The TiledImageLayer whose corresponding Sprite is to be
returned