Class GameMap

  • All Implemented Interfaces:
    Drawable, com.badlogic.gdx.utils.Disposable

    class GameMap
    extends java.lang.Object
    implements Drawable
    A GameMap represents and manages the Drawable playing Area background, principally consisting of the TiledMap.
    Author:
    ENG1 Team 23 (Cohort 3)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int height
      The height of the GameMap, in in-game metres
      private com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer renderer
      The LibGDX rendering object responsible for the rendering of the TiledMap
      private static int TILE_AXIS_LENGTH
      The fixed width and height of all tiles, in pixels
      private com.badlogic.gdx.maps.tiled.TiledMap tiledMap
      The TiledMap representing the loaded tilemap TMX file
      private int width
      The width of the GameMap, in in-game metres
    • Constructor Summary

      Constructors 
      Constructor Description
      GameMap​(java.lang.String mapPath)
      Creates a new GameMap with the given map path
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) com.badlogic.gdx.math.Vector2 bound​(com.badlogic.gdx.math.Vector2 candidate, float horizontalGutter, float verticalGutter)
      Bounds the given candidate vector along the determined tiledMap boundaries
      void dispose()
      Releases all resources used by the GameMap
      (package private) com.badlogic.gdx.utils.Array<com.badlogic.gdx.maps.objects.RectangleMapObject> getBorderObjects()
      Retrieve the "borders" layer objects from the TiledMap of the current GameMap
      void render​(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
      Renders the entire GameMap
      (package private) float scale​(float value)
      Scales the given value, specified in pixels, to in-game metres
      (package private) void updateView​(com.badlogic.gdx.graphics.OrthographicCamera gameCam)
      Instructs the OrthogonalTiledMapRenderer to update its viewing position with respect to the OrthographicCamera game camera
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • TILE_AXIS_LENGTH

        private static final int TILE_AXIS_LENGTH
        The fixed width and height of all tiles, in pixels
        See Also:
        Constant Field Values
      • tiledMap

        private final com.badlogic.gdx.maps.tiled.TiledMap tiledMap
        The TiledMap representing the loaded tilemap TMX file
        See Also:
        TmxMapLoader.load(String)
      • renderer

        private final com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer renderer
        The LibGDX rendering object responsible for the rendering of the TiledMap
        See Also:
        TiledMap
      • width

        private final int width
        The width of the GameMap, in in-game metres
      • height

        private final int height
        The height of the GameMap, in in-game metres
    • Constructor Detail

      • GameMap

        GameMap​(java.lang.String mapPath)
         throws InvalidAreaException
        Creates a new GameMap with the given map path
        Parameters:
        mapPath - The path of the map
        Throws:
        InvalidAreaException - The map was invalid could not be loaded into the area
    • Method Detail

      • getBorderObjects

        com.badlogic.gdx.utils.Array<com.badlogic.gdx.maps.objects.RectangleMapObject> getBorderObjects()
                                                                                                 throws InvalidAreaException
        Retrieve the "borders" layer objects from the TiledMap of the current GameMap
        Returns:
        The RectangleMapObject objects embedded in the requested layer
        Throws:
        InvalidAreaException
      • scale

        float scale​(float value)
        Scales the given value, specified in pixels, to in-game metres
        Parameters:
        value - The quantity to scale, in pixels
        Returns:
        The scaled quantity, in in-game metres
      • bound

        com.badlogic.gdx.math.Vector2 bound​(com.badlogic.gdx.math.Vector2 candidate,
                                            float horizontalGutter,
                                            float verticalGutter)
        Bounds the given candidate vector along the determined tiledMap boundaries
        Parameters:
        candidate - The vector to be bounded
        horizontalGutter - The gutter, specified as in-game metres, on the horizontal axis
        verticalGutter - The gutter, specified as in-game metres, on the vertical axis
        Returns:
        The bounded vector
        See Also:
        Area.bound(Vector2, float, float)
      • updateView

        void updateView​(com.badlogic.gdx.graphics.OrthographicCamera gameCam)
        Instructs the OrthogonalTiledMapRenderer to update its viewing position with respect to the OrthographicCamera game camera
        Parameters:
        gameCam - The OrthographicCamera game camera against which the Area viewport should be aligned
      • dispose

        public void dispose()
        Releases all resources used by the GameMap
        Specified by:
        dispose in interface com.badlogic.gdx.utils.Disposable
      • render

        public void render​(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
        Renders the entire GameMap
        Specified by:
        render in interface Drawable
        Parameters:
        batch - Target of the rendering operation