Class TiledMap
java.lang.Object
org.openpatch.scratch.extensions.tiled.TiledMap
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetObjectsFromLayer
(String name) Retrieves the objects from a specified layer in the tiled map.void
stampLayerToBackground
(String name) Stamps a specified layer onto the background.void
stampLayerToForeground
(String name) Stamps the specified layer to the foreground.toString()
-
Constructor Details
-
TiledMap
Constructs a new TiledMap object.- Parameters:
path
- the file path to the Tiled map XML filestage
- the stage to which this Tiled map belongs
-
-
Method Details
-
getObjectsFromLayer
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
Stamps the specified layer to the foreground.- Parameters:
name
- the name of the layer to be stamped to the foreground
-
stampLayerToBackground
Stamps a specified layer onto the background.- Parameters:
name
- the name of the layer to be stamped onto the background
-
toString
-