# TiledMap (Slick - The 2D Library)
Date: 2013-06-03

## org.newdawn.slick.tiled
Class TiledMap

    java.lang.Object
      org.newdawn.slick.tiled.TiledMap

    public class TiledMap

extends java.lang.Object

This class is intended to parse TilED maps. TilED is a generic tool for tile map editing and can be found at: http://mapeditor.org/

Author:
  kevin, Tiago Costa, Loads of others!

Nested Class Summary
`protected class` `TiledMap.GroupObject` An object from a object-group on the map
`protected class` `TiledMap.ObjectGroup` A group of objects on the map (objects layer)

Field Summary
`protected int` `height` The height of the map
`protected static int` `ISOMETRIC` Indicates an isometric map
`protected java.util.ArrayList` `layers` The list of layers defined in the map
`protected java.util.ArrayList` `objectGroups` The list of object-groups defined in the map
`protected int` `orientation` The orientation of this map
`protected static int` `ORTHOGONAL` Indicates a orthogonal map
`protected java.util.Properties` `props` the properties of the map
`protected int` `tileHeight` The height of the tiles used on the map
`protected java.util.ArrayList` `tileSets` The list of tilesets defined in the map
`protected java.lang.String` `tilesLocation` The location prefix where we can find tileset images
`protected int` `tileWidth` The width of the tiles used on the map
`protected int` `width` The width of the map

Constructor Summary
`TiledMap(java.io.InputStream in)` Load a tile map from an arbitary input stream
`TiledMap(java.io.InputStream in, java.lang.String tileSetsLocation)` Load a tile map from an arbitary input stream
`TiledMap(java.lang.String ref)` Create a new tile map based on a given TMX file
`TiledMap(java.lang.String ref, boolean loadTileSets)` Create a new tile map based on a given TMX file
`TiledMap(java.lang.String ref, java.lang.String tileSetsLocation)` Create a new tile map based on a given TMX file

Method Summary
`TileSet` `findTileSet(int gid)` Find a tile for a given global tile id
`int` `getHeight()` Get the height of the map
`int` `getLayerCount()` Retrieve a count of the number of layers available
`int` `getLayerIndex(java.lang.String name)` Get the index of the layer with given name
`java.lang.String` `getLayerProperty(int layerIndex, java.lang.String propertyName, java.lang.String def)` Get a property given to a particular layer.
`java.lang.String` `getMapProperty(java.lang.String propertyName, java.lang.String def)` Get a property given to the map.
`int` `getObjectCount(int groupID)` Returns the number of objects of a specific object-group.
`int` `getObjectGroupCount()` Returns the number of object-groups defined in the map.
`int` `getObjectHeight(int groupID, int objectID)` Returns the height of a specific object from a specific group.
`java.lang.String` `getObjectImage(int groupID, int objectID)` Retrieve the image source property for a given object
`java.lang.String` `getObjectName(int groupID, int objectID)` Return the name of a specific object from a specific group.
`java.lang.String` `getObjectProperty(int groupID, int objectID, java.lang.String propertyName, java.lang.String def)` Looks for a property with the given name and returns it's value.
`java.lang.String` `getObjectType(int groupID, int objectID)` Return the type of an specific object from a specific group.
`int` `getObjectWidth(int groupID, int objectID)` Returns the width of a specific object from a specific group.
`int` `getObjectX(int groupID, int objectID)` Returns the x-coordinate of a specific object from a specific group.
`int` `getObjectY(int groupID, int objectID)` Returns the y-coordinate of a specific object from a specific group.
`int` `getTileHeight()` Get the height of a single tile
`int` `getTileId(int x, int y, int layerIndex)` Get the global ID of a tile at specified location in the map
`Image` `getTileImage(int x, int y, int layerIndex)` Gets the Image used to draw the tile at the given x and y coordinates.
`java.lang.String` `getTileProperty(int tileID, java.lang.String propertyName, java.lang.String def)` Get a propety given to a particular tile.
`TileSet` `getTileSet(int index)` Get a tileset at a particular index in the list of sets for this map
`TileSet` `getTileSetByGID(int gid)` Get a tileset by a given global ID
`int` `getTileSetCount()` Retrieve the number of tilesets available in this map
`java.lang.String` `getTilesLocation()` Get the location of the tile images specified
`int` `getTileWidth()` Get the width of a single tile
`int` `getWidth()` Get the width of the map
`void` `render(int x, int y)` Render the whole tile map at a given location
`void` `render(int x, int y, int layer)` Render a single layer from the map
`void` `render(int x, int y, int sx, int sy, int width, int height)` Render a section of the tile map
`void` `render(int x, int y, int sx, int sy, int width, int height, boolean lineByLine)` Render a section of the tile map
`void` `render(int x, int y, int sx, int sy, int width, int height, int l, boolean lineByLine)` Render a section of the tile map
`protected void` `renderedLine(int visualY, int mapY, int layer)` Overrideable to allow other sprites to be rendered between lines of the map
`protected void` `renderIsometricMap(int x, int y, int sx, int sy, int width, int height, Layer layer, boolean lineByLine)` Render of isometric map renders.
`void` `setTileId(int x, int y, int layerIndex, int tileid)` Set the global ID of a tile at specified location in the map

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### width

    protected int width

  The width of the map

### height

    protected int height

  The height of the map

### tileWidth

    protected int tileWidth

  The width of the tiles used on the map

### tileHeight

    protected int tileHeight

  The height of the tiles used on the map

### tilesLocation

    protected java.lang.String tilesLocation

  The location prefix where we can find tileset images

### props

    protected java.util.Properties props

  the properties of the map

### tileSets

    protected java.util.ArrayList tileSets

  The list of tilesets defined in the map

### layers

    protected java.util.ArrayList layers

  The list of layers defined in the map

### objectGroups

    protected java.util.ArrayList objectGroups

  The list of object-groups defined in the map

### ORTHOGONAL

    protected static final int ORTHOGONAL

  Indicates a orthogonal map

  See Also:
    Constant Field Values

### ISOMETRIC

    protected static final int ISOMETRIC

  Indicates an isometric map

  See Also:
    Constant Field Values

### orientation

    protected int orientation

  The orientation of this map

Constructor Detail

### TiledMap

    public TiledMap(java.lang.String ref)
             throws SlickException

  Create a new tile map based on a given TMX file

  Parameters:
    `ref` - The location of the tile map to load
  Throws:
    `SlickException` - Indicates a failure to load the tilemap

### TiledMap

    public TiledMap(java.lang.String ref,
                    boolean loadTileSets)
             throws SlickException

  Create a new tile map based on a given TMX file

  Parameters:
    `ref` - The location of the tile map to load
    `loadTileSets` - True if we want to load tilesets - including their image data
  Throws:
    `SlickException` - Indicates a failure to load the tilemap

### TiledMap

    public TiledMap(java.lang.String ref,
                    java.lang.String tileSetsLocation)
             throws SlickException

  Create a new tile map based on a given TMX file

  Parameters:
    `ref` - The location of the tile map to load
    `tileSetsLocation` - The location where we can find the tileset images and other resources
  Throws:
    `SlickException` - Indicates a failure to load the tilemap

### TiledMap

    public TiledMap(java.io.InputStream in)
             throws SlickException

  Load a tile map from an arbitary input stream

  Parameters:
    `in` - The input stream to load from
  Throws:
    `SlickException` - Indicates a failure to load the tilemap

### TiledMap

    public TiledMap(java.io.InputStream in,
                    java.lang.String tileSetsLocation)
             throws SlickException

  Load a tile map from an arbitary input stream

  Parameters:
    `in` - The input stream to load from
    `tileSetsLocation` - The location at which we can find tileset images
  Throws:
    `SlickException` - Indicates a failure to load the tilemap

Method Detail

### getTilesLocation

    public java.lang.String getTilesLocation()

  Get the location of the tile images specified

  Returns:
    The location of the tile images specified as a resource reference prefix

### getLayerIndex

    public int getLayerIndex(java.lang.String name)

  Get the index of the layer with given name

  Parameters:
    `name` - The name of the tile to search for
  Returns:
    The index of the layer or -1 if there is no layer with given name

### getTileImage

    public Image getTileImage(int x,
                              int y,
                              int layerIndex)

  Gets the Image used to draw the tile at the given x and y coordinates.

  Parameters:
    `x` - The x coordinate of the tile whose image should be retrieved
    `y` - The y coordinate of the tile whose image should be retrieved
    `layerIndex` - The index of the layer on which the tile whose image should be retrieve exists
  Returns:
    The image used to draw the specified tile or null if there is no image for the specified tile.

### getWidth

    public int getWidth()

  Get the width of the map

  Returns:
    The width of the map (in tiles)

### getHeight

    public int getHeight()

  Get the height of the map

  Returns:
    The height of the map (in tiles)

### getTileHeight

    public int getTileHeight()

  Get the height of a single tile

  Returns:
    The height of a single tile (in pixels)

### getTileWidth

    public int getTileWidth()

  Get the width of a single tile

  Returns:
    The height of a single tile (in pixels)

### getTileId

    public int getTileId(int x,
                         int y,
                         int layerIndex)

  Get the global ID of a tile at specified location in the map

  Parameters:
    `x` - The x location of the tile
    `y` - The y location of the tile
    `layerIndex` - The index of the layer to retireve the tile from
  Returns:
    The global ID of the tile

### setTileId

    public void setTileId(int x,
                          int y,
                          int layerIndex,
                          int tileid)

  Set the global ID of a tile at specified location in the map

  Parameters:
    `x` - The x location of the tile
    `y` - The y location of the tile
    `layerIndex` - The index of the layer to set the new tileid
    `tileid` - The tileid to be set

### getMapProperty

    public java.lang.String getMapProperty(java.lang.String propertyName,
                                           java.lang.String def)

  Get a property given to the map. Note that this method will not perform well and should not be used as part of the default code path in the game loop.

  Parameters:
    `propertyName` - The name of the property of the map to retrieve
    `def` - The default value to return
  Returns:
    The value assigned to the property on the map (or the default value if none is supplied)

### getLayerProperty

    public java.lang.String getLayerProperty(int layerIndex,
                                             java.lang.String propertyName,
                                             java.lang.String def)

  Get a property given to a particular layer. Note that this method will not perform well and should not be used as part of the default code path in the game loop.

  Parameters:
    `layerIndex` - The index of the layer to retrieve
    `propertyName` - The name of the property of this layer to retrieve
    `def` - The default value to return
  Returns:
    The value assigned to the property on the layer (or the default value if none is supplied)

### getTileProperty

    public java.lang.String getTileProperty(int tileID,
                                            java.lang.String propertyName,
                                            java.lang.String def)

  Get a propety given to a particular tile. Note that this method will not perform well and should not be used as part of the default code path in the game loop.

  Parameters:
    `tileID` - The global ID of the tile to retrieve
    `propertyName` - The name of the property to retireve
    `def` - The default value to return
  Returns:
    The value assigned to the property on the tile (or the default value if none is supplied)

### render

    public void render(int x,
                       int y)

  Render the whole tile map at a given location

  Parameters:
    `x` - The x location to render at
    `y` - The y location to render at

### render

    public void render(int x,
                       int y,
                       int layer)

  Render a single layer from the map

  Parameters:
    `x` - The x location to render at
    `y` - The y location to render at
    `layer` - The layer to render

### render

    public void render(int x,
                       int y,
                       int sx,
                       int sy,
                       int width,
                       int height)

  Render a section of the tile map

  Parameters:
    `x` - The x location to render at
    `y` - The y location to render at
    `sx` - The x tile location to start rendering
    `sy` - The y tile location to start rendering
    `width` - The width of the section to render (in tiles)
    `height` - The height of the secton to render (in tiles)

### render

    public void render(int x,
                       int y,
                       int sx,
                       int sy,
                       int width,
                       int height,
                       int l,
                       boolean lineByLine)

  Render a section of the tile map

  Parameters:
    `x` - The x location to render at
    `y` - The y location to render at
    `sx` - The x tile location to start rendering
    `sy` - The y tile location to start rendering
    `width` - The width of the section to render (in tiles)
    `height` - The height of the secton to render (in tiles)
    `l` - The index of the layer to render
    `lineByLine` - True if we should render line by line, i.e. giving us a chance to render something else between lines (@see `renderedLine(int, int, int)`

### render

    public void render(int x,
                       int y,
                       int sx,
                       int sy,
                       int width,
                       int height,
                       boolean lineByLine)

  Render a section of the tile map

  Parameters:
    `x` - The x location to render at
    `y` - The y location to render at
    `sx` - The x tile location to start rendering
    `sy` - The y tile location to start rendering
    `width` - The width of the section to render (in tiles)
    `height` - The height of the secton to render (in tiles)
    `lineByLine` - True if we should render line by line, i.e. giving us a chance to render something else between lines (@see `renderedLine(int, int, int)`

### renderIsometricMap

    protected void renderIsometricMap(int x,
                                      int y,
                                      int sx,
                                      int sy,
                                      int width,
                                      int height,
                                      Layer layer,
                                      boolean lineByLine)

  Render of isometric map renders.

  Parameters:
    `x` - The x location to render at
    `y` - The y location to render at
    `sx` - The x tile location to start rendering
    `sy` - The y tile location to start rendering
    `width` - The width of the section to render (in tiles)
    `height` - The height of the section to render (in tiles)
    `layer` - if this is null all layers are rendered, if not only the selected layer is renderered
    `lineByLine` - True if we should render line by line, i.e. giving us a chance to render something else between lines (@see `renderedLine(int, int, int)` TODO: [Isometric map] Render stuff between lines, concept of line differs from ortho maps

### getLayerCount

    public int getLayerCount()

  Retrieve a count of the number of layers available

  Returns:
    The number of layers available in this map

### getTileSetCount

    public int getTileSetCount()

  Retrieve the number of tilesets available in this map

  Returns:
    The number of tilesets available in this map

### getTileSet

    public TileSet getTileSet(int index)

  Get a tileset at a particular index in the list of sets for this map

  Parameters:
    `index` - The index of the tileset.
  Returns:
    The TileSet requested

### getTileSetByGID

    public TileSet getTileSetByGID(int gid)

  Get a tileset by a given global ID

  Parameters:
    `gid` - The global ID of the tileset to retrieve
  Returns:
    The tileset requested or null if no tileset matches

### findTileSet

    public TileSet findTileSet(int gid)

  Find a tile for a given global tile id

  Parameters:
    `gid` - The global tile id we're looking for
  Returns:
    The tileset in which that tile lives or null if the gid is not defined

### renderedLine

    protected void renderedLine(int visualY,
                                int mapY,
                                int layer)

  Overrideable to allow other sprites to be rendered between lines of the map

  Parameters:
    `visualY` - The visual Y coordinate, i.e. 0->height
    `mapY` - The map Y coordinate, i.e. y->y+height
    `layer` - The layer being rendered

### getObjectGroupCount

    public int getObjectGroupCount()

  Returns the number of object-groups defined in the map.

  Returns:
    Number of object-groups on the map

### getObjectCount

    public int getObjectCount(int groupID)

  Returns the number of objects of a specific object-group.

  Parameters:
    `groupID` - The index of this object-group
  Returns:
    Number of the objects in the object-group or -1, when error occurred.

### getObjectName

    public java.lang.String getObjectName(int groupID,
                                          int objectID)

  Return the name of a specific object from a specific group.

  Parameters:
    `groupID` - Index of a group
    `objectID` - Index of an object
  Returns:
    The name of an object or null, when error occurred

### getObjectType

    public java.lang.String getObjectType(int groupID,
                                          int objectID)

  Return the type of an specific object from a specific group.

  Parameters:
    `groupID` - Index of a group
    `objectID` - Index of an object
  Returns:
    The type of an object or null, when error occurred

### getObjectX

    public int getObjectX(int groupID,
                          int objectID)

  Returns the x-coordinate of a specific object from a specific group.

  Parameters:
    `groupID` - Index of a group
    `objectID` - Index of an object
  Returns:
    The x-coordinate of an object, or -1, when error occurred

### getObjectY

    public int getObjectY(int groupID,
                          int objectID)

  Returns the y-coordinate of a specific object from a specific group.

  Parameters:
    `groupID` - Index of a group
    `objectID` - Index of an object
  Returns:
    The y-coordinate of an object, or -1, when error occurred

### getObjectWidth

    public int getObjectWidth(int groupID,
                              int objectID)

  Returns the width of a specific object from a specific group.

  Parameters:
    `groupID` - Index of a group
    `objectID` - Index of an object
  Returns:
    The width of an object, or -1, when error occurred

### getObjectHeight

    public int getObjectHeight(int groupID,
                               int objectID)

  Returns the height of a specific object from a specific group.

  Parameters:
    `groupID` - Index of a group
    `objectID` - Index of an object
  Returns:
    The height of an object, or -1, when error occurred

### getObjectImage

    public java.lang.String getObjectImage(int groupID,
                                           int objectID)

  Retrieve the image source property for a given object

  Parameters:
    `groupID` - Index of a group
    `objectID` - Index of an object
  Returns:
    The image source reference or null if one isn't defined

### getObjectProperty

    public java.lang.String getObjectProperty(int groupID,
                                              int objectID,
                                              java.lang.String propertyName,
                                              java.lang.String def)

  Looks for a property with the given name and returns it's value. If no property is found, def is returned.

  Parameters:
    `groupID` - Index of a group
    `objectID` - Index of an object
    `propertyName` - Name of a property
    `def` - default value to return, if no property is found
  Returns:
    The value of the property with the given name or def, if there is no property with that name.

Copyright © 2006 New Dawn Software. All Rights Reserved.