Package bagel.map

Class TiledMap

java.lang.Object
bagel.map.TiledMap

public class TiledMap extends Object
Loads a tile map as produced by Tiled Map Editor.

Allows looking up properties of tiles in the map as well as basic rendering.

  • Constructor Summary

    Constructors
    Constructor
    Description
    TiledMap(String tmxFile)
    Build the tiled map from the provided .tmx file.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    draw(double windowX, double windowY, double mapX, double mapY, double width, double height)
    Draws the rectangular region of the map with top left at (mapX, mapY) and bottom right at (mapX + width, mapY + height).
    Returns all polylines associated with this map.
    int
    Returns the height of the entire map, in pixels.
    getProperty(int x, int y, String property)
    Returns the string value of the provided property at the given (x, y) pixel coordinate of the map.
    getProperty(int x, int y, String property, String defaultValue)
    Returns the string value of the provided property at the given (x, y) pixel coordinate of the map.
    boolean
    getPropertyBoolean(int x, int y, String property, boolean defaultValue)
    Returns the Boolean value of the provided property at the given (x, y) pixel coordinate of the map.
    double
    getPropertyDouble(int x, int y, String property, double defaultValue)
    Returns the double value of the provided property at the given (x, y) pixel coordinate of the map.
    int
    getPropertyInt(int x, int y, String property, int defaultValue)
    Returns the integer value of the provided property at the given (x, y) pixel coordinate of the map.
    int
    Returns the height of an individual tile in the map, in pixels.
    int
    Returns the width of an individual tile in the map, in pixels.
    int
    Returns the width of the entire map, in pixels.
    boolean
    hasProperty(int x, int y, String property)
    Returns true if the tile at the given (x, y) pixel coordinate of the map has the given property.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TiledMap

      public TiledMap(String tmxFile)
      Build the tiled map from the provided .tmx file.
  • Method Details

    • getTileWidth

      public int getTileWidth()
      Returns the width of an individual tile in the map, in pixels.
    • getTileHeight

      public int getTileHeight()
      Returns the height of an individual tile in the map, in pixels.
    • getWidth

      public int getWidth()
      Returns the width of the entire map, in pixels.
    • getHeight

      public int getHeight()
      Returns the height of the entire map, in pixels.
    • getProperty

      public String getProperty(int x, int y, String property)
      Returns the string value of the provided property at the given (x, y) pixel coordinate of the map.
    • getProperty

      public String getProperty(int x, int y, String property, String defaultValue)
      Returns the string value of the provided property at the given (x, y) pixel coordinate of the map.

      If the property is missing, returns the default.

    • getPropertyInt

      public int getPropertyInt(int x, int y, String property, int defaultValue)
      Returns the integer value of the provided property at the given (x, y) pixel coordinate of the map. If the value is not a valid integer, throws BagelError.

      defaultValue is the value that will be returned if the tile has no such property.

    • getPropertyDouble

      public double getPropertyDouble(int x, int y, String property, double defaultValue)
      Returns the double value of the provided property at the given (x, y) pixel coordinate of the map. If the value is not a valid double, throws BagelError.

      defaultValue is the value that will be returned if the tile has no such property.

    • getPropertyBoolean

      public boolean getPropertyBoolean(int x, int y, String property, boolean defaultValue)
      Returns the Boolean value of the provided property at the given (x, y) pixel coordinate of the map. If the value is not a valid boolean, throws BagelError.

      defaultValue is the value that will be returned if the tile has no such property.

    • hasProperty

      public boolean hasProperty(int x, int y, String property)
      Returns true if the tile at the given (x, y) pixel coordinate of the map has the given property.
    • getAllPolylines

      public List<List<Point>> getAllPolylines()
      Returns all polylines associated with this map. A polyline is simply a list of points.
      Returns:
      List of polylines
    • draw

      public void draw(double windowX, double windowY, double mapX, double mapY, double width, double height)
      Draws the rectangular region of the map with top left at (mapX, mapY) and bottom right at (mapX + width, mapY + height). The top left will be drawn on the window at (windowX, windowY).
      Parameters:
      windowX - The x coordinate of the window to start drawing the map region from
      windowY - The y coordinate of the window to start drawing the map region from
      mapX - The x coordinate of the map to start drawing from
      mapY - The y coordinate of the map to start drawing from
      width - The width of the region to render
      height - The height of the region to render