Class MapUtilities
public final class MapUtilities
Static utility methods for working with TMX-style maps, map objects, tiles and tile coordinates. Most overloads default to the map of the currently
loaded environment.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Path2DconvertPolyshapeToPath(IMapObject mapObject) Converts a polyline or polygon map object to aPath2Din absolute (map-space) coordinates.static IMapObjectfindMapObject(IMap map, int id) Searches the supplied map for a map object with the given id.static ITilesetfindTileSet(IMap map, ITile tile) Searches for the tile set that contains the specified tile, identified by the grid id.getAbsolutePolyshapePoints(IMapObject mapObject) Returns the points of a polyline or polygon map object translated to absolute (map-space) coordinates.static Rectangle2DgetBounds(IMapObject... objects) Computes the combined axis-aligned bounding box of the supplied map objects.static Point2DgetMapLocation(IMap map, Point tileLocation) Converts a tile coordinate to its pixel-space top-left location on the given map.static intgetMaxMapId(IMap map) Returns the maximum id of any map object on the given map.static PointGet the corresponding tile for a given pixel map location.static PointGet the corresponding tile for a given pixel map location.static Rectangle2DgetTileBoundingBox(int x, int y) Returns the bounding box of the tile at the given tile coordinate on the current environment's map.static Rectangle2DgetTileBoundingBox(IMap map, int x, int y) Returns the bounding box of the tile at the given tile coordinate on the supplied map.static Rectangle2DgetTileBoundingBox(IMap map, Point2D mapLocation) Returns the bounding box of the tile that contains the given pixel-space location on the supplied map.static Rectangle2DgetTileBoundingBox(IMap map, Rectangle2D box) Snaps the given pixel-space rectangle to the bounding box of the tiles it covers on the given map.static Rectangle2DgetTileBoundingBox(IMap map, Point tile) Returns the bounding box of the tile at the given tile coordinate on the supplied map.static Rectangle2DgetTileBoundingBox(Point2D mapLocation) Returns the bounding box of the tile that contains the given pixel-space location on the current environment's map.static Rectangle2DgetTileBoundingBox(Point tile) Returns the bounding box of the tile at the given tile coordinate on the current environment's map.static Point2DgetTileImageLocation(IMap map, ITile tile) Gets the top-left map location at which the image of a tile is rendered.getTilesByPixelLocation(IMap map, Point2D location) Returns all tiles from any tile layer on the given map that contain the supplied pixel-space location.static ITilegetTopMostTile(IMap map, Point2D location) Returns the top-most non-empty tile at the given pixel-space location on the supplied map.static ITilegetTopMostTile(IMap map, Point point) Returns the top-most non-empty tile at the given tile coordinate on the supplied map.static ITilegetTopMostTile(Point2D location) Returns the top-most non-empty tile at the given pixel-space location on the current environment's map.static ITilegetTopMostTile(Point point) Returns the top-most non-empty tile at the given tile coordinate on the current environment's map.static booleanisStaggeredRowOrColumn(StaggerIndex staggerIndex, int index) Check if the row or column with the given index is staggered.
-
Method Details
-
getBounds
Computes the combined axis-aligned bounding box of the supplied map objects.- Parameters:
objects- the map objects whose bounding boxes are merged- Returns:
- the union bounding box
-
getMaxMapId
-
getTileBoundingBox
Snaps the given pixel-space rectangle to the bounding box of the tiles it covers on the given map.- Parameters:
map- the map providing tile size and orientationbox- the pixel-space rectangle to snap- Returns:
- the bounding box that covers all enclosed tiles
-
getTile
Get the corresponding tile for a given pixel map location. This is an overload taking the Map from the current environment to calculate a tile location.- Parameters:
mapLocation- the pixel map location.- Returns:
- The x / y tile coordinate for the given location.
- See Also:
-
getTile
-
isStaggeredRowOrColumn
Check if the row or column with the given index is staggered.- Parameters:
staggerIndex- the staggerIndex property of the map. Every second row (or column, depending on theStaggerAxisof the map is staggered half a tile.index- the index of the current row or column for which we want to determine if it's staggered or not.- Returns:
- a boolean representing if the row or column with the given index is staggered.
-
getMapLocation
-
getTileImageLocation
-
getTilesByPixelLocation
Returns all tiles from any tile layer on the given map that contain the supplied pixel-space location.- Parameters:
map- the map to inspectlocation- the pixel-space location- Returns:
- the matching tiles, ordered by layer (bottom to top)
-
getTopMostTile
-
getTopMostTile
-
getTopMostTile
-
getTopMostTile
-
findTileSet
-
convertPolyshapeToPath
Converts a polyline or polygon map object to aPath2Din absolute (map-space) coordinates.- Parameters:
mapObject- the polyline or polygon map object- Returns:
- the resulting path, or
nullif the object is not a polyline/polygon or contains no points
-
getAbsolutePolyshapePoints
Returns the points of a polyline or polygon map object translated to absolute (map-space) coordinates.- Parameters:
mapObject- the polyline or polygon map object- Returns:
- the absolute points, or an empty list if the object is not a polyline/polygon
-
findMapObject
Searches the supplied map for a map object with the given id.- Parameters:
map- the map to searchid- the id to look up- Returns:
- the matching map object, or
nullif none exists
-
getTileBoundingBox
Returns the bounding box of the tile that contains the given pixel-space location on the current environment's map.- Parameters:
mapLocation- the pixel-space location- Returns:
- the enclosing tile's bounding box
-
getTileBoundingBox
Returns the bounding box of the tile that contains the given pixel-space location on the supplied map.- Parameters:
map- the map providing tile size and orientationmapLocation- the pixel-space location- Returns:
- the enclosing tile's bounding box, or an empty rectangle if
mapisnull
-
getTileBoundingBox
Returns the bounding box of the tile at the given tile coordinate on the current environment's map.- Parameters:
x- the tile x coordinatey- the tile y coordinate- Returns:
- the tile's bounding box
-
getTileBoundingBox
Returns the bounding box of the tile at the given tile coordinate on the supplied map.- Parameters:
map- the map providing tile size and orientationx- the tile x coordinatey- the tile y coordinate- Returns:
- the tile's bounding box
-
getTileBoundingBox
Returns the bounding box of the tile at the given tile coordinate on the current environment's map.- Parameters:
tile- the tile coordinate- Returns:
- the tile's bounding box
-
getTileBoundingBox
Returns the bounding box of the tile at the given tile coordinate on the supplied map.- Parameters:
map- the map providing tile size and orientationtile- the tile coordinate- Returns:
- the tile's bounding box, or an empty rectangle if
mapisnull
-