com.badlogic.gdx.maps.MapProperties Java Examples
The following examples show how to use
com.badlogic.gdx.maps.MapProperties.
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 |
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: Box2DMapObjectParser.java From Entitas-Java with MIT License | 6 votes |
/** * internal method for easier access of {@link MapProperties} * * @param properties the {@link MapProperties} from which to get a property * @param property the key of the desired property * @param defaultValue the default value to return in case the value of the given key cannot be returned * @return the property value associated with the given property key */ @SuppressWarnings("unchecked") private <T> T getProperty(MapProperties properties, String property, T defaultValue) { if (properties.get(property) == null) return defaultValue; if (defaultValue.getClass() == Float.class) if (properties.get(property).getClass() == Integer.class) return (T) new Float(properties.get(property, Integer.class)); else if (properties.get(property).getClass() == Float.class) return (T) new Float(properties.get(property, Float.class)); else return (T) new Float(Float.parseFloat(properties.get(property, String.class))); else if (defaultValue.getClass() == Short.class) return (T) new Short(Short.parseShort(properties.get(property, String.class))); else if (defaultValue.getClass() == Boolean.class) return (T) new Boolean(Boolean.parseBoolean(properties.get(property, String.class))); else return (T) properties.get(property, defaultValue.getClass()); }
Example #3
Source File: UAtlasTmxMapLoader.java From uracer-kotd with Apache License 2.0 | 5 votes |
protected void loadProperties (MapProperties properties, Element element) { if (element.getName().equals("properties")) { for (Element property : element.getChildrenByName("property")) { String name = property.getAttribute("name", null); String value = property.getAttribute("value", null); if (value == null) { value = property.getText(); } properties.put(name, value); } } }
Example #4
Source File: NavTmxMapLoader.java From pathfinding with Apache License 2.0 | 5 votes |
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); }
Example #5
Source File: UAtlasTmxMapLoader.java From uracer-kotd with Apache License 2.0 | 4 votes |
protected TiledMap loadMap (Element root, FileHandle tmxFile, AtlasResolver resolver, AtlasTiledMapLoaderParameters parameter) { TiledMap map = new TiledMap(); String mapOrientation = root.getAttribute("orientation", null); int mapWidth = root.getIntAttribute("width", 0); int mapHeight = root.getIntAttribute("height", 0); int tileWidth = root.getIntAttribute("tilewidth", 0); int tileHeight = root.getIntAttribute("tileheight", 0); String mapBackgroundColor = root.getAttribute("backgroundcolor", null); MapProperties mapProperties = map.getProperties(); if (mapOrientation != null) { mapProperties.put("orientation", mapOrientation); } mapProperties.put("width", mapWidth); mapProperties.put("height", mapHeight); mapProperties.put("tilewidth", tileWidth); mapProperties.put("tileheight", tileHeight); if (mapBackgroundColor != null) { mapProperties.put("backgroundcolor", mapBackgroundColor); } mapTileWidth = tileWidth; mapTileHeight = tileHeight; mapWidthInPixels = mapWidth * tileWidth; mapHeightInPixels = mapHeight * tileHeight; for (int i = 0, j = root.getChildCount(); i < j; i++) { Element element = root.getChild(i); String elementName = element.getName(); if (elementName.equals("properties")) { loadProperties(map.getProperties(), element); } else if (elementName.equals("tileset")) { loadTileset(map, element, tmxFile, resolver, parameter); } else if (elementName.equals("layer")) { loadTileLayer(map, element); } else if (elementName.equals("objectgroup")) { loadObjectGroup(map, element); } } return map; }