Class Maps
A container class for managing map resources. This class extends the ResourcesContainer class, specifically for IMap objects.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassThis class provides the API to simplify the generation of map resources from code. -
Method Summary
Modifier and TypeMethodDescriptiongenerate(IMapOrientation orientation, String name, int width, int height, int tileWidth, int tileHeight, ITileset... tilesets) Starts a process that allows the generation of maps from code.protected StringGets an alias for the specified resourceName.static booleanisSupported(String fileName) Checks if the specified file name has a supported extension.protected IMapLoads an IMap resource from the specified URL.Methods inherited from class ResourcesContainer
add, add, addClearedListener, addContainerListener, clear, contains, contains, contains, count, get, get, get, get, get, get, get, getAll, getAsync, getAsync, getResources, remove, remove, removeClearedListener, removeContainerListener, tryGet, tryGet
-
Method Details
-
isSupported
Checks if the specified file name has a supported extension.- Parameters:
fileName- The name of the file to check.- Returns:
- true if the file has a supported extension, false otherwise.
-
generate
public Maps.MapGenerator generate(IMapOrientation orientation, String name, int width, int height, int tileWidth, int tileHeight, ITileset... tilesets) Starts a process that allows the generation of maps from code.
Notice that you must call this within a try-with block or ensure that
Maps.MapGenerator.close()is called before using the generated map instance.Example usage:
IMap map; try (MapGenerator generator = Resources.maps().generate("name", 50, 50, 16, 16, Resources.tilesets().get("tileset.tsx"))) { ITileLayer tileLayer = generator.addTileLayer(RenderType.GROUND, (x, y) -> { if (x == y) { // draw a diagonal in another tile color return 2; } // fill the entire map with this tile return 1; }); // set an explicit tile at a location tileLayer.setTile(10, 10, 3); // add a collision box to the map generator.add(new CollisionBox(0, 64, 100, 10)); map = generator.getMap(); }- Parameters:
orientation- The orientation of the map to be generated.name- The name of the map to be generated.width- The width (in tiles).height- The height (in tiles).tileWidth- The width of a tile (in pixels).tileHeight- The height of a tile (in pixels).tilesets- Tilesets that will be used by the map.- Returns:
- A
MapGeneratorinstance used to add additional layers or objects to the map.
-
load
Loads an IMap resource from the specified URL.- Specified by:
loadin classResourcesContainer<IMap>- Parameters:
resourceName- The URL of the resource to load.- Returns:
- The loaded IMap resource.
- Throws:
IOException- If an I/O error occurs.URISyntaxException- If the URL is not formatted correctly.
-
getAlias
Description copied from class:ResourcesContainerGets an alias for the specified resourceName. Note that the process of providing an alias is up to the ResourceContainer implementation.- Overrides:
getAliasin classResourcesContainer<IMap>- Parameters:
resourceName- The original name of the resource.resource- The resource.- Returns:
- An alias for the specified resource.
-