[libgdx]Editable tiled map

Typing “tile” in search gives us more than 40 pages of result, so I am aware, that my question won’t be original. But half of them are out of date or doesn’t help.

I’m trying to write tower defense game based on TiledMap and crucial for me is to edit map from game level. Is there any way to do this with with tmx map or I need to write my own format… If second, what is the best way to do this? I expect to have not more than 200x200 tiles(more likely 100x100).
I will be grateful for any help.

Have mine!


public class TileMap {
	
	private int width, height;
	
	private Tile[][] map;
	
	public TileMap(int width, int height) {
		this.width = width;
		this.height = height;
		initializeTiles(width, height);
	}
	
	private void initializeTiles(int width, int height) {
		map = new Tile[width][height];
		for(int i = 0; i < width; i++) {
			for(int k = 0; k < height; k++) {
				map[i][k] = new Tile();
			}
		}
	}
	
	public void setTile(Tile tile, int x, int y) {
		map[x][y] = tile;
	}
	
	public Tile getTile(int x, int y) {
		if (x < 0 || x >= width || y < 0 || y >= height) {
			return null;
		}
		return map[x][y];
	}
	
	public int getWidth() {
		return width;
	}
	
	public int getHeight() {
		return height;
	}
}

The Tile class can be anything you’d want, and it’s easy to get the Tile for altering, or you can make an entirely new Tile, in any cell.
I’ve always designed in a way where the Tile itself doesn’t know it’s position, but that’s personal preference and a design choice.
You can render this fella easily, by simply looping through each cell.

Thanks a lot.

Luckily, this happened, so I will wait for new API and check if it satisfies me.