Setting tiles in maps on-the-fly (Pull Request?) #719
Replies: 8 comments
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). // create a basic map
TmxMap map = new TmxMap(MapOrientations.ORTHOGONAL);
map.setRenderOrder(RenderOrder.RIGHT_DOWN);
map.setTileWidth(16);
map.setTileHeight(16);
map.setWidth(100);
map.setHeight(100);
map.setTiledVersion("1.1.5");
map.setName("random");
Tileset tileset = new Tileset(Resources.tilesets().get("sample"));
map.getTilesets().add(tileset);
List<Tile> tiles = new ArrayList<>();
for (int y = 0; y < 100; y++) {
for (int x = 0; x < 100; x++) {
int tile = 3;
if (SOME CONDITION TO SET A DIFFERENT TILE) {
tile = 4;
}
tiles.add(new Tile(tile));
}
}
TileData data;
try {
data = new TileData(tiles, 100, 100, TileData.Encoding.CSV, TileData.Compression.NONE);
data.setValue(TileData.encode(data));
} catch (IOException e) {
data = null;
e.printStackTrace();
}
TileLayer ground = new TileLayer(data);
ground.setRenderType(RenderType.GROUND);
ground.setWidth(100);
ground.setHeight(100);
map.addLayer(ground); We should maybe simplify and improve the existing API here but I don't see a real reason for a different implementation. Any addition/contribution here would be very welcome :) |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). [
data = (TileData)TileData.class.getMethod("TileData", (new ArrayList<Tile>()).getClass(), Integer.class, Integer.class, TileData.Encoding.class, TileData.Compression.class).invoke(null, tiles, 100, 100, TileData.Encoding.CSV, TileData.Compression.NONE);
] |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). IMap generatedMap;
try (MapGenerator generator = Resources.maps().generate(MapOrientations.ORTHOGONAL, "mymap", 100, 100, 16, 16, Resources.tilesets().get("tileset.tsx"))) {
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, 50, 100, 10));
generatedMap = generator.getMap();
} This API will be available with the next release of the engine ~~ |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022).
Posted: 2020-04-01 21:31:03
User: escho [] (age: 943 days 🙌; posts: 6)
If I understand properly, LITIengine has no capability yet to set map tiles on-the-fly.
If this is true, would the devs / community be interested in my attempt to do so & a pull request?
Note: I realize there is a serialization capability. I'm talking about direct on-the-fly native LITIengine map generation capabilities.
I'm going to write it anyway non-native, so I thought I could do a native win-win.
Because of the groundwork already laid out, it would be higher level layer of code that converts java-like programming interpretation of maps into the existing serialization. i.e
and maybe it's too bulky, but HashMap does work with Point2D keys. It's a miracle of java really.
Beta Was this translation helpful? Give feedback.
All reactions