public class TiledMap extends Object implements TiledParserListener
Modifier and Type | Field and Description |
---|---|
protected List<TiledObjectGroup> |
objectGroups |
protected List<TileLayer> |
tileLayers |
protected 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)
Constructs a map from a TMX file
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsProperty(String propertyName)
Returns if the map contains the specified property
|
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 width,
int height)
Draws a section of the map at the specified coordinates
|
void |
draw(Graphics g,
int x,
int y,
int startTileX,
int startTileY,
int width,
int height,
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(String name)
Returns the index of the
TileLayer with the given name |
TiledObjectGroup |
getObjectGroup(String name)
Returns the
TiledObjectGroup with the given name |
List<TiledObjectGroup> |
getObjectGroups()
Returns the
TiledObjectGroup s of this map |
Orientation |
getOrientation()
Returns the
Orientation of this map |
String |
getProperty(String propertyName)
Returns the value of a specified property
|
Tile |
getTile(int tileId)
Returns the
Tile for the given tile ID |
int |
getTileHeight()
Returns the height of tiles in pixels
|
TileLayer |
getTileLayer(String name)
Returns the
TileLayer with the given name |
List<TileLayer> |
getTileLayers()
Returns the
TileLayer s of this map |
List<Tileset> |
getTilesets()
Returns the
Tileset s of this map |
int |
getTileWidth()
Returns the width of tiles in pixels
|
int |
getWidth()
Returns the width of the map in tiles
|
void |
onBeginParsing(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 width,
int height)
Developers can override this method to implement sprite rendering
|
void |
onMapPropertyParsed(String propertyName,
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 width,
int height)
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(String propertyName,
String value)
Sets the value of a specified property
|
protected List<TiledObjectGroup> objectGroups
public TiledMap()
public TiledMap(com.badlogic.gdx.files.FileHandle fileHandle) throws IOException
fileHandle
- A FileHandle
to a .tmx fileIOException
- Thrown if the map file could not be parsedpublic TiledMap(com.badlogic.gdx.files.FileHandle fileHandle, boolean loadTilesets) throws IOException
fileHandle
- A FileHandle
to a .tmx fileloadTilesets
- True if the tileset images should be loadedIOException
- Thrown if the map file could not be parsedpublic 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 width, int height)
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 fromwidth
- The amount of tiles across the x axis to renderheight
- The amount of tiles across the y axis to renderpublic void draw(Graphics g, int x, int y, int startTileX, int startTileY, int width, int height, 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 fromwidth
- The amount of tiles across the x axis to renderheight
- 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 width, int height)
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 startedwidth
- The amount of tiles that were rendered along the X axisheight
- The amount of tiles that were rendered along the Y axisprotected void onLayerRendered(Graphics g, TileLayer layer, int startTileX, int startTileY, int width, int height)
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 startedwidth
- The amount of tiles that were rendered along the X axisheight
- The amount of tiles that were rendered along the Y axispublic boolean containsProperty(String propertyName)
propertyName
- The property name to search forpublic String getProperty(String propertyName)
propertyName
- The property name to search forpublic void setProperty(String propertyName, String value)
propertyName
- The property name to set the value forvalue
- The value of the property to setpublic void onBeginParsing(String orientation, com.badlogic.gdx.graphics.Color backgroundColor, int width, int height, int tileWidth, int tileHeight)
onBeginParsing
in interface TiledParserListener
public void onMapPropertyParsed(String propertyName, 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(String name)
TileLayer
with the given namename
- The name to search forTileLayer
public TiledObjectGroup getObjectGroup(String name)
TiledObjectGroup
with the given namename
- The name to search forTiledObjectGroup
public int getLayerIndex(String name)
TileLayer
with the given namename
- The name to search forTileLayer
public Tile getTile(int tileId)
Tile
for the given tile IDtileId
- The tile ID to search forTile
with the given IDpublic Orientation getOrientation()
Orientation
of this mappublic int getWidth()
public int getHeight()
public int getTileWidth()
public int getTileHeight()
public List<Tileset> getTilesets()
Tileset
s of this mappublic List<TileLayer> getTileLayers()
TileLayer
s of this mappublic List<TiledObjectGroup> getObjectGroups()
TiledObjectGroup
s of this mappublic com.badlogic.gdx.graphics.Color getBackgroundColor()
Color
of the mapCopyright © 2014. All rights reserved.