public class TiledMap extends java.lang.Object implements TiledParserListener
TileLayer
s
to improve render speedsModifier and Type | Field and Description |
---|---|
protected java.util.List<Layer> |
layers |
protected java.util.Map<java.lang.String,TiledObjectGroup> |
objectGroups |
protected java.util.List<Tileset> |
tilesets |
Constructor and Description |
---|
TiledMap()
Constructs an empty map
|
TiledMap(com.badlogic.gdx.files.FileHandle fileHandle)
Constructs a map from a TMX file
|
TiledMap(com.badlogic.gdx.files.FileHandle fileHandle,
boolean loadTilesets,
boolean cacheLayers)
Constructs a map from a TMX file
|
TiledMap(TiledParser parser,
com.badlogic.gdx.files.FileHandle fileHandle,
boolean loadTilesets,
boolean cacheLayers)
Constructs a map from a TMX file
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsProperty(java.lang.String propertyName)
Returns if the map contains the specified property
|
void |
dispose()
Releases any resources used by this TiledMap
|
void |
draw(Graphics g,
int x,
int y)
Draws the entire map at the specified coordinates
|
void |
draw(Graphics g,
int x,
int y,
int layer)
Draws a layer of the map at the specified coordinates
|
void |
draw(Graphics g,
int x,
int y,
int startTileX,
int startTileY,
int widthInTiles,
int heightInTiles)
Draws a section of the map at the specified coordinates
|
void |
draw(Graphics g,
int x,
int y,
int startTileX,
int startTileY,
int widthInTiles,
int heightInTiles,
int layer)
Draws a section of a specified layer of the map at the specified
coordinates
|
com.badlogic.gdx.graphics.Color |
getBackgroundColor()
Returns the background
Color of the map |
int |
getHeight()
Returns the height of the map in tiles
|
int |
getLayerIndex(java.lang.String name)
Returns the index of the
TileLayer or TiledObjectGroup
with the given name |
java.util.List<Layer> |
getLayers()
Returns the
Layer s of this map |
TiledObjectGroup |
getObjectGroup(java.lang.String name)
Returns the
TiledObjectGroup with the given name |
java.util.Collection<TiledObjectGroup> |
getObjectGroups()
Returns all the
TiledObjectGroup s in this map |
Orientation |
getOrientation()
Returns the
Orientation of this map |
int |
getPixelHeight()
Return the height of the map in pixels
|
int |
getPixelWidth()
Returns the width of the map in pixels
|
java.lang.String |
getProperty(java.lang.String propertyName)
Returns the value of a specified property
|
Tile |
getTile(int tileId)
Returns the
Tile for the given tile ID |
Tile |
getTile(int x,
int y,
int layer)
Returns the
Tile at the given coordinate on a specific layer |
int |
getTileHeight()
Returns the height of tiles in pixels
|
TileLayer |
getTileLayer(int index)
Returns the
TileLayer at the given index |
TileLayer |
getTileLayer(java.lang.String name)
Returns the
TileLayer with the given name |
java.util.List<Tileset> |
getTilesets()
Returns the
Tileset s of this map |
int |
getTileWidth()
Returns the width of tiles in pixels
|
int |
getTotalObjectGroups()
Returns the total amount of
TiledObjectGroup instances |
int |
getTotalTilesetsLoaded()
Returns the total amount of
Tileset s loaded |
int |
getWidth()
Returns the width of the map in tiles
|
boolean |
isTilesetsLoaded()
Returns if the
Tileset images have been loaded |
void |
loadTileset(int tilesetIndex)
Loads a specific
Tileset |
void |
loadTilesets()
Loads all
Tileset s for this map if they are not already loaded |
void |
onBeginParsing(java.lang.String orientation,
com.badlogic.gdx.graphics.Color backgroundColor,
int width,
int height,
int tileWidth,
int tileHeight) |
protected void |
onLayerRendered(Graphics g,
TileLayer layer,
int startTileX,
int startTileY,
int widthInTiles,
int heightInTiles)
Developers can override this method to implement sprite rendering
|
void |
onMapPropertyParsed(java.lang.String propertyName,
java.lang.String value) |
void |
onObjectGroupParsed(TiledObjectGroup parsedObjectGroup) |
void |
onTileLayerParsed(TileLayer parsedLayer) |
void |
onTilePropertiesParsed(Tile tile) |
void |
onTilesetParsed(Tileset parsedTileset) |
protected boolean |
preLayerRendered(Graphics g,
TileLayer layer,
int startTileX,
int startTileY,
int widthInTiles,
int heightInTiles)
Developers can override this method which is called before a layer is
rendered
To prevent the layer from rendering, return false from this method.
|
void |
setProperty(java.lang.String propertyName,
java.lang.String value)
Sets the value of a specified property
|
void |
setTiledObjectGroupRenderer(TiledObjectGroupRenderer tiledObjectGroupRenderer)
Sets the
TiledObjectGroupRenderer implementation to use for
rendering |
void |
setTileLayerRenderer(TileLayerRenderer tileLayerRenderer)
Sets the
TileLayerRenderer implementation to use for rendering |
protected java.util.List<Tileset> tilesets
protected java.util.List<Layer> layers
protected java.util.Map<java.lang.String,TiledObjectGroup> objectGroups
public TiledMap()
public TiledMap(com.badlogic.gdx.files.FileHandle fileHandle) throws TiledException
fileHandle
- A FileHandle
to a .tmx fileTiledException
- Thrown if there were issues with the loaded mappublic TiledMap(com.badlogic.gdx.files.FileHandle fileHandle, boolean loadTilesets, boolean cacheLayers) throws TiledException
fileHandle
- A FileHandle
to a .tmx fileloadTilesets
- True if the tileset images should be loaded and the map
pre-renderedTiledException
- Thrown if there were issues with the loaded mappublic TiledMap(TiledParser parser, com.badlogic.gdx.files.FileHandle fileHandle, boolean loadTilesets, boolean cacheLayers) throws TiledException
parser
- An existing TiledParser
instancefileHandle
- A FileHandle
to a .tmx fileloadTilesets
- True if the tileset images should be loaded and the map
pre-renderedTiledException
- Thrown if there were issues with the loaded mappublic boolean isTilesetsLoaded()
Tileset
images have been loadedpublic int getTotalTilesetsLoaded()
Tileset
s loadedpublic void loadTileset(int tilesetIndex)
Tileset
tilesetIndex
- public void loadTilesets()
Tileset
s for this map if they are not already loadedpublic void draw(Graphics g, int x, int y)
g
- The Graphics
context available for renderingx
- The x coordinate to render aty
- The y coordinate to render atpublic void draw(Graphics g, int x, int y, int layer)
g
- The Graphics
context available for renderingx
- The x coordinate to render aty
- The y coordinate to render atlayer
- The layer index to renderpublic void draw(Graphics g, int x, int y, int startTileX, int startTileY, int widthInTiles, int heightInTiles)
g
- The Graphics
context available for renderingx
- The x coordinate to render aty
- The y coordinate to render atstartTileX
- The x tile coordinate in the map to start fromstartTileY
- The y tile coordinate in the map to start fromwidthInTiles
- The amount of tiles across the x axis to renderheightInTiles
- The amount of tiles across the y axis to renderpublic void draw(Graphics g, int x, int y, int startTileX, int startTileY, int widthInTiles, int heightInTiles, int layer)
g
- The Graphics
context available for renderingx
- The x coordinate to render aty
- The y coordinate to render atstartTileX
- The x tile coordinate in the map to start fromstartTileY
- The y tile coordinate in the map to start fromwidthInTiles
- The amount of tiles across the x axis to renderheightInTiles
- The amount of tiles across the y axis to renderlayer
- The layer index to renderprotected boolean preLayerRendered(Graphics g, TileLayer layer, int startTileX, int startTileY, int widthInTiles, int heightInTiles)
g
- The Graphics
context used for renderinglayer
- The TileLayer
which was just renderedstartTileX
- The x coordinate in tiles where rendering startedstartTileY
- The y coordinate in tiles where rendering startedwidthInTiles
- The amount of tiles that were rendered along the X axisheightInTiles
- The amount of tiles that were rendered along the Y axisprotected void onLayerRendered(Graphics g, TileLayer layer, int startTileX, int startTileY, int widthInTiles, int heightInTiles)
g
- The Graphics
context used for renderinglayer
- The TileLayer
which was just renderedstartTileX
- The x coordinate in tiles where rendering startedstartTileY
- The y coordinate in tiles where rendering startedwidthInTiles
- The amount of tiles that were rendered along the X axisheightInTiles
- The amount of tiles that were rendered along the Y axispublic boolean containsProperty(java.lang.String propertyName)
propertyName
- The property name to search forpublic java.lang.String getProperty(java.lang.String propertyName)
propertyName
- The property name to search forpublic void setProperty(java.lang.String propertyName, java.lang.String value)
propertyName
- The property name to set the value forvalue
- The value of the property to setpublic void onBeginParsing(java.lang.String orientation, com.badlogic.gdx.graphics.Color backgroundColor, int width, int height, int tileWidth, int tileHeight)
onBeginParsing
in interface TiledParserListener
public void onMapPropertyParsed(java.lang.String propertyName, java.lang.String value)
onMapPropertyParsed
in interface TiledParserListener
public void onTilePropertiesParsed(Tile tile)
onTilePropertiesParsed
in interface TiledParserListener
public void onTilesetParsed(Tileset parsedTileset)
onTilesetParsed
in interface TiledParserListener
public void onTileLayerParsed(TileLayer parsedLayer)
onTileLayerParsed
in interface TiledParserListener
public void onObjectGroupParsed(TiledObjectGroup parsedObjectGroup)
onObjectGroupParsed
in interface TiledParserListener
public TileLayer getTileLayer(java.lang.String name)
TileLayer
with the given namename
- The name to search forTileLayer
public TileLayer getTileLayer(int index)
TileLayer
at the given indexindex
- The index of the layerpublic TiledObjectGroup getObjectGroup(java.lang.String name)
TiledObjectGroup
with the given namename
- The name to search forTiledObjectGroup
public java.util.Collection<TiledObjectGroup> getObjectGroups()
TiledObjectGroup
s in this mapTiledObjectGroup
spublic int getLayerIndex(java.lang.String name)
TileLayer
or TiledObjectGroup
with the given namename
- The name to search forTileLayer
or
TiledObjectGroup
public Tile getTile(int tileId)
Tile
for the given tile IDtileId
- The tile ID to search forTile
with the given IDpublic Tile getTile(int x, int y, int layer)
Tile
at the given coordinate on a specific layerx
- The x coordinate (in tiles)y
- The y coordinate (in tiles)layer
- The layer indexTile
public void dispose()
public Orientation getOrientation()
Orientation
of this mappublic int getWidth()
public int getHeight()
public int getTileWidth()
public int getTileHeight()
public int getPixelWidth()
public int getPixelHeight()
public java.util.List<Tileset> getTilesets()
Tileset
s of this mappublic int getTotalObjectGroups()
TiledObjectGroup
instancespublic com.badlogic.gdx.graphics.Color getBackgroundColor()
Color
of the mappublic void setTileLayerRenderer(TileLayerRenderer tileLayerRenderer)
TileLayerRenderer
implementation to use for renderingtileLayerRenderer
- The TileLayerRenderer
to usepublic void setTiledObjectGroupRenderer(TiledObjectGroupRenderer tiledObjectGroupRenderer)
TiledObjectGroupRenderer
implementation to use for
renderingtiledObjectGroupRenderer
- The TiledObjectGroupRenderer
to use