2
\$\begingroup\$

I am making a Terraria-style sidescrolling game with an open world. I am using a TiledMap to render all of the tiles. If I want to remove a tile, like if it is broken, how would I stop it from being rendered?

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

first we make an instance of map layer that contain the tile that we want to remove

for example:

TiledMap map=new TiledMap();

//lets say we want to remove some tile from layer with index of 0

TiledMapTileLayer layer=map.getLayers().get(0);

//so if we need to remove the tile in layer at position 0,1

layer.getCell(0, 1).setTile(null);

\$\endgroup\$
2
  • \$\begingroup\$ Cool! I assume I can use setTile for creating new tiles? I think I heard somewhere that you can only set tiles that are already in the map. \$\endgroup\$
    – Plato2000
    Commented May 15, 2014 at 22:14
  • \$\begingroup\$ Yes u can creating tiles or even the whole Map in run time , search in google for creating tiled map programmatically \$\endgroup\$ Commented Jun 13, 2014 at 19:25
0
\$\begingroup\$

I'm not to familial with TiledMaps but when I create a proceduraly generated 2d game I use a boolean array and in my render method check if the boolean at the index is true if it is draw the tile if not don't draw the tile. But after reading the javadoc I see that a method removeTileSet(int index) so possibly when you break something get the index and try to removeTileSet(x);

\$\endgroup\$

You must log in to answer this question.

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