Class Maps.MapGenerator

java.lang.Object
de.gurkenlabs.litiengine.resources.Maps.MapGenerator
All Implemented Interfaces:
java.lang.AutoCloseable
Enclosing class:
Maps

public class Maps.MapGenerator
extends java.lang.Object
implements java.lang.AutoCloseable
This class provides the API to simplify the generation of map resources from code.
  • Method Summary

    Modifier and TypeMethodDescription
    IMapObjectadd​(IEntity entity)
    Adds a MapObject created by the specified entity to the map of this instance.
    IMapObjectadd​(IMapObject mapObject)
    Adds the specified map object to the map of this instance.
    IMapObjectadd​(IMapObjectLayer layer, IEntity entity)
    Adds a MapObject created by the specified entity to the map of this instance.
    IMapObjectadd​(IMapObjectLayer layer, IMapObject mapObject)
    Adds the specified map object to the map of this instance.
    ITileLayeraddTileLayer​(RenderType renderType, java.util.function.IntBinaryOperator tileCallback)
    Adds a new tile tile layer to the generated map of this instance.
    voidclose()
    It is crucial to call this before using the generated map of this instance.
    IMapgetMap()
    Gets the map generated by this instance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getMap

      public IMap getMap()
      Gets the map generated by this instance.

      Make sure this instance is closed before using the map in your game.

      Returns:
      The map generated by this instance.
      See Also:
      close()
    • addTileLayer

      public ITileLayer addTileLayer​(RenderType renderType, java.util.function.IntBinaryOperator tileCallback)
      Adds a new tile tile layer to the generated map of this instance. Example for a tileCallback:
      
       (x, y) -> {
         if (x == y) {
           // draw a diagonal in another tile color
           return 2;
         }
       
         // fill the entire map with this tile
         return 1;
       }
       
      Parameters:
      renderType - The rendertype of the added layer.
      tileCallback - The callback that defines which tile gid will be assigned at the specified x, y grid coordinates.
      Returns:
      The newly added tile layer.
    • add

      public IMapObject add​(IEntity entity)
      Adds a MapObject created by the specified entity to the map of this instance.

      If no layer has been added yet, a default MapObjectLayer will be created by this method.

      Parameters:
      entity - The entity to be converted to a map object and added to the first MapObjectLayer of the generated map.
      Returns:
      The created map object.
    • add

      public IMapObject add​(IMapObjectLayer layer, IEntity entity)
      Adds a MapObject created by the specified entity to the map of this instance.
      Parameters:
      layer - The layer to which the map object will be added.
      entity - The entity to be converted to a map object and added to the specified MapObjectLayer.
      Returns:
      The created map object.
    • add

      public IMapObject add​(IMapObject mapObject)
      Adds the specified map object to the map of this instance.

      If no layer has been added yet, a default MapObjectLayer will be created by this method.

      Parameters:
      mapObject - The mapObject to be added to the first MapObjectLayer of the generated map.
      Returns:
      The added map object.
    • add

      public IMapObject add​(IMapObjectLayer layer, IMapObject mapObject)
      Adds the specified map object to the map of this instance.
      Parameters:
      layer - The layer to which the map object will be added.
      mapObject - The mapObject to be added to the specified MapObjectLayer.
      Returns:
      The added map object.
    • close

      public void close()
      It is crucial to call this before using the generated map of this instance.

      This will call the finish method on the map instance and make sure that the generated map is available over the resources API.

      Specified by:
      close in interface java.lang.AutoCloseable
      See Also:
      TmxMap.finish(URL)