com.badlogic.gdx.maps.tiled.TiledMapTile Java Examples

The following examples show how to use com.badlogic.gdx.maps.tiled.TiledMapTile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MyNavTmxMapLoader.java    From Norii with Apache License 2.0 6 votes vote down vote up
private GridCell[][] createGridCells(TiledMap map, Element element, int width, int height) {
	int[] ids = getTileIds(element, width, height);
	TiledMapTileSets tilesets = map.getTileSets();
	GridCell[][] nodes = new GridCell[width][height];
	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
			int id = ids[y * width + x];
			TiledMapTile tile = tilesets.getTile(id & ~MASK_CLEAR);
			
			GridCell cell = new GridCell(x, height - 1 - y, false);
			if (tile != null) {
				MapProperties tileProp = tile.getProperties();
				
				String walkableProp = tileProp.get(navigationProperty, navigationClosedValue, String.class);
				cell.setWalkable( !walkableProp.equals(navigationClosedValue) );
			}
			nodes[cell.getX()][cell.getY()] = cell;
		}
	}
	return nodes;
}
 
Example #2
Source File: UAtlasTmxMapLoader.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
protected void loadTileLayer (TiledMap map, Element element) {
	if (element.getName().equals("layer")) {
		String name = element.getAttribute("name", null);
		int width = element.getIntAttribute("width", 0);
		int height = element.getIntAttribute("height", 0);
		int tileWidth = element.getParent().getIntAttribute("tilewidth", 0);
		int tileHeight = element.getParent().getIntAttribute("tileheight", 0);
		boolean visible = element.getIntAttribute("visible", 1) == 1;
		float opacity = element.getFloatAttribute("opacity", 1.0f);
		TiledMapTileLayer layer = new TiledMapTileLayer(width, height, tileWidth, tileHeight);
		layer.setVisible(visible);
		layer.setOpacity(opacity);
		layer.setName(name);

		int[] ids = TmxMapHelper.getTileIds(element, width, height);
		TiledMapTileSets tilesets = map.getTileSets();
		for (int y = 0; y < height; y++) {
			for (int x = 0; x < width; x++) {
				int id = ids[y * width + x];
				boolean flipHorizontally = ((id & FLAG_FLIP_HORIZONTALLY) != 0);
				boolean flipVertically = ((id & FLAG_FLIP_VERTICALLY) != 0);
				boolean flipDiagonally = ((id & FLAG_FLIP_DIAGONALLY) != 0);

				TiledMapTile tile = tilesets.getTile(id & ~MASK_CLEAR);
				if (tile != null) {
					Cell cell = createTileLayerCell(flipHorizontally, flipVertically, flipDiagonally);
					cell.setTile(tile);
					layer.setCell(x, yUp ? height - 1 - y : y, cell);
				}
			}
		}

		Element properties = element.getChildByName("properties");
		if (properties != null) {
			loadProperties(layer.getProperties(), properties);
		}
		map.getLayers().add(layer);
	}
}
 
Example #3
Source File: NavTmxMapLoader.java    From pathfinding with Apache License 2.0 5 votes vote down vote up
private void loadNavigationLayer(TiledMap map, Element element, String layerName){
	int width = element.getIntAttribute("width", 0);
	int height = element.getIntAttribute("height", 0);
	
	int[] ids = getTileIds(element, width, height);
	TiledMapTileSets tilesets = map.getTileSets();
	GridCell[][] nodes = new GridCell[width][height];
	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
			int id = ids[y * width + x];
			TiledMapTile tile = tilesets.getTile(id & ~MASK_CLEAR);
			
			GridCell cell = new GridCell(x, height - 1 - y, false);
			if (tile != null) {
				MapProperties tileProp = tile.getProperties();
				
				String walkableProp = tileProp.get(navigationProperty, navigationClosedValue, String.class);
				cell.setWalkable( !walkableProp.equals(navigationClosedValue) );
			}
			nodes[cell.getX()][cell.getY()] = cell;
		}
	}
	
	NavigationTiledMapLayer layer = new NavigationTiledMapLayer(nodes);
	layer.setName(layerName);
	layer.setVisible(false);

	Element properties = element.getChildByName("properties");
	if (properties != null) {
		loadProperties(layer.getProperties(), properties);
	}
	map.getLayers().add(layer);
}