public class TiledMap
extends java.lang.Object
Constructor and Description |
---|
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(TiledMapData tiledMapData,
boolean loadTilesetTextures,
boolean cacheLayers) |
TiledMap(TiledParser parser,
com.badlogic.gdx.files.FileHandle fileHandle,
boolean loadTilesetTextures,
boolean cacheLayers)
Constructs a map from a TMX file
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsAnimatedTiles()
Returns if this map contains animated tiles
|
boolean |
containsProperty(java.lang.String propertyName)
Returns if the map contains the specified property
|
void |
dispose()
Releases any resources used by this TiledMap including tilesets
|
void |
dispose(boolean disposeTilesets)
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 |
int |
getLayerIndexIgnoreCase(java.lang.String name)
Returns the index of the
TileLayer or TiledObjectGroup
with the given name ignoring upper/lowercase differences |
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
|
int |
getSideLength()
Returns the stagger side length of this map
|
StaggerAxis |
getStaggerAxis()
Returns the
StaggerAxis of this map |
StaggerIndex |
getStaggerIndex()
Returns the
StaggerIndex of this map |
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 |
getWidth()
Returns the width of the map in tiles
|
boolean |
isTilesetTexturesLoaded()
Returns if the
Tileset images have been loaded |
void |
loadTilesetTextures()
Loads all
Tileset textures for this map if they are not already loaded |
void |
loadTilesetTextures(com.badlogic.gdx.assets.AssetManager assetManager)
Loads all
Tileset textures for this map if they are not already loaded |
protected void |
onLayerRendered(Graphics g,
TileLayer layer,
int startTileX,
int startTileY,
int widthInTiles,
int heightInTiles)
Developers can override this method to implement sprite rendering
|
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 |
void |
update(float delta)
Updates map elements such as animated tiles
|
public TiledMap(com.badlogic.gdx.files.FileHandle fileHandle)
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)
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 loadTilesetTextures, boolean cacheLayers)
parser
- An existing TiledParser
instancefileHandle
- A FileHandle
to a .tmx fileloadTilesetTextures
- True if the tileset images should be loadedTiledException
- Thrown if there were issues with the loaded mappublic TiledMap(TiledMapData tiledMapData, boolean loadTilesetTextures, boolean cacheLayers)
public boolean isTilesetTexturesLoaded()
Tileset
images have been loadedpublic void loadTilesetTextures()
Tileset
textures for this map if they are not already loadedpublic void loadTilesetTextures(com.badlogic.gdx.assets.AssetManager assetManager)
Tileset
textures for this map if they are not already loadedassetManager
- The AssetManager
to usepublic void update(float delta)
delta
- The time since the last frame (in seconds)public 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 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 int getLayerIndexIgnoreCase(java.lang.String name)
TileLayer
or TiledObjectGroup
with the given name ignoring upper/lowercase differencesname
- 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 void dispose(boolean disposeTilesets)
disposeTilesets
- True if tilesets should also be disposedpublic Orientation getOrientation()
Orientation
of this mappublic StaggerAxis getStaggerAxis()
StaggerAxis
of this mappublic StaggerIndex getStaggerIndex()
StaggerIndex
of this mappublic int getSideLength()
public 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 usepublic boolean containsAnimatedTiles()