3
\$\begingroup\$

I'm trying to make a Side-Scrolling game that will allow you to place/remove tiles. I'm using the TileMap Editor to render the custom Tilemap but is there any way to add tiles? I have it where I can remove the tiles with .setTile(null) but is there anyway to get the properties from a tile in the TileMap Editor so that it can get the Texture/Tile to use so it can place the tile?!

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You can create a Cell and fill that with a tile from the TileMapTileSet, then set that cell at (x, y) coordinates in a particular Layer.

For example, the following code sets the tile at (32, 64) in a layer to tile 42 from tile set tileset_name;

TiledMapTileLayer layer = (TiledMapTileLayer)map.getLayers().get("some_layer_name");
Cell cell = new Cell();
TiledMapTileSet tileSet = map.getTileSets().getTileSet("tileset_name");
cell.setTile(tileSet.getTile(42)); /* or some other id, identifying the tile */
layer.setCell(32, 64, cell); // 32 and 64 being x and y coordinates

In the above code map is a TiledMap.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .