Class TmxMap

java.lang.Object
de.gurkenlabs.litiengine.environment.tilemap.xml.CustomPropertyProvider
de.gurkenlabs.litiengine.environment.tilemap.xml.TmxMap
All Implemented Interfaces:
ICustomPropertyProvider, ILayerList, IMap, Comparable<IMap>

public final class TmxMap extends CustomPropertyProvider implements IMap
JAXB-bound representation of a Tiled (TMX) map. Implements IMap so the loaded data integrates seamlessly with the engine's map/environment API and serves as the in-memory model when the engine reads .tmx files.
  • Field Details

    • FILE_EXTENSION

      public static final String FILE_EXTENSION
      File extension used by Tiled map files.
      See Also:
    • MAX_MAJOR

      public static final int MAX_MAJOR
      Maximum supported TMX major version.
      See Also:
    • MAX_MINOR

      public static final int MAX_MINOR
      Maximum supported TMX minor version.
      See Also:
    • MIN_MAJOR

      public static final int MIN_MAJOR
      Minimum supported TMX major version.
      See Also:
    • MIN_MINOR

      public static final int MIN_MINOR
      Minimum supported TMX minor version.
      See Also:
  • Constructor Details

    • TmxMap

      public TmxMap()
      Creates a new TmxMap. Intended for XML deserialization; populated fields will be initialized by JAXB.
    • TmxMap

      public TmxMap(IMapOrientation orientation)
      Creates a new TmxMap with the given map orientation, defaulting the render order to right-down and the Tiled version to the maximum supported value.
      Parameters:
      orientation - the map orientation
    • TmxMap

      public TmxMap(TmxMap original)
      Copy constructor for the TmxMap class. Creates a new instance of the TmxMap class by copying the properties from the provided TmxMap object.
      Parameters:
      original - The original TmxMap object to copy from.
  • Method Details

    • getImageLayers

      public List<IImageLayer> getImageLayers()
      Description copied from interface: ILayerList
      Gets the IImageLayers contained in a Layer list.
      Specified by:
      getImageLayers in interface ILayerList
      Returns:
      a List of all IImageLayers
    • getNextObjectId

      public int getNextObjectId()
      Gets the next object id.
      Specified by:
      getNextObjectId in interface IMap
      Returns:
      the next object id
    • getNextLayerId

      public int getNextLayerId()
      Description copied from interface: IMap
      Gets the next available layer id, used to assign unique ids to newly created layers.
      Specified by:
      getNextLayerId in interface IMap
      Returns:
      the next layer id
    • getOrientation

      public IMapOrientation getOrientation()
      Description copied from interface: IMap
      Gets the orientation.
      Specified by:
      getOrientation in interface IMap
      Returns:
      the orientation
    • setOrientation

      public void setOrientation(IMapOrientation orientation)
      Sets the map's orientation.
      Parameters:
      orientation - the orientation; must not be null
    • getPath

      public URL getPath()
      Description copied from interface: IMap
      Gets the source URL the map was loaded from.
      Specified by:
      getPath in interface IMap
      Returns:
      the source URL
    • setPath

      public void setPath(URL path)
      Sets the source URL the map was loaded from.
      Parameters:
      path - the source URL
    • getRenderOrder

      public RenderOrder getRenderOrder()
      Description copied from interface: IMap
      Gets the order in which orthogonal tile coordinates are rendered.
      Specified by:
      getRenderOrder in interface IMap
      Returns:
      the render order declared by the map
    • setRenderOrder

      public void setRenderOrder(RenderOrder renderorder)
      Sets the render order used when drawing the map's tile layers.
      Parameters:
      renderorder - the render order
    • getMapObjectLayers

      public List<IMapObjectLayer> getMapObjectLayers()
      Returns an unmodifiable snapshot of all map object layers, including layers nested in groups. Changes to the map after this call are visible only in a newly requested snapshot.
      Specified by:
      getMapObjectLayers in interface ILayerList
      Returns:
      an unmodifiable recursive snapshot of the map object layers
    • getSizeInPixels

      public Dimension getSizeInPixels()
      Description copied from interface: IMap
      Gets the size in pixels.
      Specified by:
      getSizeInPixels in interface IMap
      Returns:
      the size in pixels
    • getBounds

      public Rectangle2D getBounds()
      Description copied from interface: IMap
      Gets the bounding rectangle of the map in pixels.
      Specified by:
      getBounds in interface IMap
      Returns:
      the bounding rectangle
    • getSizeInTiles

      public Dimension getSizeInTiles()
      Description copied from interface: IMap
      Gets the width and height in tiles.
      Specified by:
      getSizeInTiles in interface IMap
      Returns:
      the map size in tiles
    • getTileLayers

      public List<ITileLayer> getTileLayers()
      Description copied from interface: ILayerList
      Gets the ITileLayers contained in a Layer list.
      Specified by:
      getTileLayers in interface ILayerList
      Returns:
      a List of all ITileLayers
    • getTilesets

      public List<ITileset> getTilesets()
      Description copied from interface: IMap
      Gets the tilesets.
      Specified by:
      getTilesets in interface IMap
      Returns:
      the tilesets
    • getTilesetEntry

      public ITilesetEntry getTilesetEntry(int gid)
      Description copied from interface: IMap
      Gets the tileset entry referenced by the supplied global tile id.
      Specified by:
      getTilesetEntry in interface IMap
      Parameters:
      gid - the global tile id
      Returns:
      the matching tileset entry, or null if no tileset contains the id
    • getTileSize

      public Dimension getTileSize()
      Description copied from interface: IMap
      Gets the tile size.
      Specified by:
      getTileSize in interface IMap
      Returns:
      the tile size
    • getParallaxOrigin

      public Point2D getParallaxOrigin()
      Description copied from interface: IMap
      Gets the coordinates of the parallax origin in pixels.
      Specified by:
      getParallaxOrigin in interface IMap
      Returns:
      The parallax origin.
    • getTileWidth

      public int getTileWidth()
      Description copied from interface: IMap
      Gets the horizontal tile size.
      Specified by:
      getTileWidth in interface IMap
      Returns:
      the horizontal tile size
    • setTileWidth

      public void setTileWidth(int tilewidth)
      Sets the width of a single tile in pixels.
      Parameters:
      tilewidth - the tile width
    • getTileHeight

      public int getTileHeight()
      Description copied from interface: IMap
      Gets the vertical tile size.
      Specified by:
      getTileHeight in interface IMap
      Returns:
      the vertical tile size
    • setTileHeight

      public void setTileHeight(int tileheight)
      Sets the height of a single tile in pixels.
      Parameters:
      tileheight - the tile height
    • getVersion

      public double getVersion()
      Description copied from interface: IMap
      Gets the version.
      Specified by:
      getVersion in interface IMap
      Returns:
      the version
    • setVersion

      public void setVersion(double version)
      Sets the TMX format version of this map.
      Parameters:
      version - the version
    • getTiledVersion

      public String getTiledVersion()
      Description copied from interface: IMap
      Gets the Tiled editor version string the map was saved with.
      Specified by:
      getTiledVersion in interface IMap
      Returns:
      the Tiled version string
    • setTiledVersion

      public void setTiledVersion(String tiledversion)
      Sets the Tiled editor version string of this map.
      Parameters:
      tiledversion - the Tiled version string
    • getGroupLayers

      public List<IGroupLayer> getGroupLayers()
      Description copied from interface: ILayerList
      Gets the IGroupLayers contained in a Layer list.
      Specified by:
      getGroupLayers in interface ILayerList
      Returns:
      a List of all IGroupLayers
    • getName

      public String getName()
      Description copied from interface: IMap
      Gets the display name of this map.
      Specified by:
      getName in interface IMap
      Returns:
      the map name
    • setName

      public void setName(String name)
      Description copied from interface: IMap
      Sets the name.
      Specified by:
      setName in interface IMap
      Parameters:
      name - the new name
    • getWidth

      public int getWidth()
      Description copied from interface: IMap
      Gets the map width in tiles.
      Specified by:
      getWidth in interface IMap
      Returns:
      the width in tiles
    • setWidth

      public void setWidth(int width)
      Sets the map width in tiles.
      Parameters:
      width - the width in tiles
    • getHeight

      public int getHeight()
      Description copied from interface: IMap
      Gets the map height in tiles.
      Specified by:
      getHeight in interface IMap
      Returns:
      the height in tiles
    • setHeight

      public void setHeight(int height)
      Sets the map height in tiles.
      Parameters:
      height - the height in tiles
    • getHexSideLength

      public int getHexSideLength()
      Description copied from interface: IMap
      Gets the straight edges' length for hexagonal maps.
      Specified by:
      getHexSideLength in interface IMap
      Returns:
      the hex side length
    • setHexSideLength

      public void setHexSideLength(int hexSideLength)
      Sets the hex side length used for hexagonal maps.
      Parameters:
      hexSideLength - the hex side length
    • getStaggerAxis

      public StaggerAxis getStaggerAxis()
      Description copied from interface: IMap
      Gets the axis along which hexagonal or staggered rows are offset.
      Specified by:
      getStaggerAxis in interface IMap
      Returns:
      the staggering axis
    • setStaggerAxis

      public void setStaggerAxis(StaggerAxis staggerAxis)
      Sets the stagger axis used for staggered and hexagonal maps.
      Parameters:
      staggerAxis - the stagger axis
    • getStaggerIndex

      public StaggerIndex getStaggerIndex()
      Description copied from interface: IMap
      Gets whether even or odd indexes are staggered.
      Specified by:
      getStaggerIndex in interface IMap
      Returns:
      the staggering index
    • setStaggerIndex

      public void setStaggerIndex(StaggerIndex staggerIndex)
      Sets the stagger index used for staggered and hexagonal maps.
      Parameters:
      staggerIndex - the stagger index
    • finish

      public void finish(URL location) throws TmxException
      Throws:
      TmxException
    • addLayer

      public void addLayer(ILayer layer)
      Description copied from interface: ILayerList
      Adds an ILayer to the Layer list.
      Specified by:
      addLayer in interface ILayerList
      Parameters:
      layer - the layer to be added
    • addLayer

      public void addLayer(int index, ILayer layer)
      Description copied from interface: ILayerList
      Adds an ILayer to the Layer list at the given index.
      Specified by:
      addLayer in interface ILayerList
      Parameters:
      index - the index
      layer - the layer to be added
    • removeLayer

      public void removeLayer(ILayer layer)
      Description copied from interface: ILayerList
      Removes an ILayer from the Layer list.
      Specified by:
      removeLayer in interface ILayerList
      Parameters:
      layer - the layer to be removed
    • removeLayer

      public void removeLayer(int index)
      Description copied from interface: ILayerList
      Removes a layer from the Layer list.
      Specified by:
      removeLayer in interface ILayerList
      Parameters:
      index - the index of the layer to be removed
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object anObject)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getRenderLayers

      public List<ILayer> getRenderLayers()
      Description copied from interface: ILayerList
      Gets all render layers in the Layer list.
      Specified by:
      getRenderLayers in interface ILayerList
      Returns:
      a List of ILayers
    • getExternalTilesets

      public List<Tileset> getExternalTilesets()
      Returns the list of external tilesets referenced by this map (i.e. tilesets defined in separate .tsx files).
      Returns:
      the list of external tilesets
    • getBackgroundColor

      public Color getBackgroundColor()
      Description copied from interface: IMap
      Gets the background color of the map.
      Specified by:
      getBackgroundColor in interface IMap
      Returns:
      the background color
    • isInfinite

      public boolean isInfinite()
      Description copied from interface: IMap
      Returns whether this is an infinite map (i.e. composed of chunks rather than a fixed-size grid).
      Specified by:
      isInfinite in interface IMap
      Returns:
      true if the map is infinite