Class TiledMap

java.lang.Object
org.openpatch.scratch.extensions.tiled.TiledMap

public class TiledMap extends Object
The TiledMap class represents a map created using the Tiled map editor. It provides methods to load the map from an XML file, retrieve objects from layers, and stamp layers onto the foreground or background of a stage.

Example usage:


 TiledMap map = new TiledMap("assets/map.tmx", stage);
 map.stampLayerToForeground("foreground");

 for (MapObject object : map.getObjectsFromLayer("objects")) {
  if (object.type.equals("player")) {
   Player p = new Player(object.x, object.y);
   stage.addSprite(p);
  }
 }

 
  • Constructor Details

    • TiledMap

      public TiledMap(String path, Stage stage)
      Constructs a new TiledMap object.
      Parameters:
      path - the file path to the Tiled map XML file
      stage - the stage to which this Tiled map belongs
  • Method Details

    • getObjectsFromLayer

      public MapObject[] getObjectsFromLayer(String name)
      Retrieves the objects from a specified layer in the tiled map.
      Parameters:
      name - the name of the layer from which to retrieve objects
      Returns:
      an array of MapObject from the specified layer, or null if the layer does not exist
    • stampLayerToForeground

      public void stampLayerToForeground(String name)
      Stamps the specified layer to the foreground.
      Parameters:
      name - the name of the layer to be stamped to the foreground
    • stampLayerToBackground

      public void stampLayerToBackground(String name)
      Stamps a specified layer onto the background.
      Parameters:
      name - the name of the layer to be stamped onto the background
    • toString

      public String toString()
      Overrides:
      toString in class Object