/** Returns the object for the given key, casting it to clazz. * @param key the key of the object * @param defaultValue the default value * @param clazz the class of the object * @return the object or the defaultValue if the object is not in the map * @throws ClassCastException if the object with the given key is not of type clazz */ public <T> T get (String key, T defaultValue, Class<T> clazz) { Object object = get(key); return object == null ? defaultValue : (T)object; }
/** Returns the object for the given key, casting it to clazz. * @param key the key of the object * @param defaultValue the default value * @param clazz the class of the object * @return the object or the defaultValue if the object is not in the map * @throws ClassCastException if the object with the given key is not of type clazz */ public <T> T get (String key, T defaultValue, Class<T> clazz) { Object object = get(key); return object == null ? defaultValue : (T)object; }
/** Returns the object for the given key, casting it to clazz. * @param key the key of the object * @param clazz the class of the object * @return the object or null if the object is not in the map * @throws ClassCastException if the object with the given key is not of type clazz */ public <T> T get (String key, Class<T> clazz) { return (T)get(key); }
/** Returns the object for the given key, casting it to clazz. * @param key the key of the object * @param clazz the class of the object * @return the object or null if the object is not in the map * @throws ClassCastException if the object with the given key is not of type clazz */ public <T> T get (String key, Class<T> clazz) { return (T)get(key); }
/** Constructs a Tile Set layout. The tile set image contained in the baseDir should be the original tile set images before * being processed by {@link TiledMapPacker} (the ones actually read by Tiled). * @param tileset the tile set to process * @param baseDir the directory in which the tile set image is stored */ protected TileSetLayout (int firstgid, TiledMapTileSet tileset, FileHandle baseDir) throws IOException { int tileWidth = tileset.getProperties().get("tilewidth", Integer.class); int tileHeight = tileset.getProperties().get("tileheight", Integer.class); int margin = tileset.getProperties().get("margin", Integer.class); int spacing = tileset.getProperties().get("spacing", Integer.class); this.firstgid = firstgid; image = ImageIO.read(baseDir.child(tileset.getProperties().get("imagesource", String.class)).read()); imageTilePositions = new IntMap<Vector2>(); // fill the tile regions int x, y, tile = 0; numRows = 0; numCols = 0; int stopWidth = image.getWidth() - tileWidth; int stopHeight = image.getHeight() - tileHeight; for (y = margin; y <= stopHeight; y += tileHeight + spacing) { for (x = margin; x <= stopWidth; x += tileWidth + spacing) { if (y == margin) numCols++; imageTilePositions.put(tile, new Vector2(x, y)); tile++; } numRows++; } numTiles = numRows * numCols; }
/** Constructs a Tile Set layout. The tile set image contained in the baseDir should be the original tile set images before * being processed by {@link TiledMapPacker} (the ones actually read by Tiled). * @param tileset the tile set to process * @param baseDir the directory in which the tile set image is stored */ protected TileSetLayout (int firstgid, TiledMapTileSet tileset, FileHandle baseDir) throws IOException { int tileWidth = tileset.getProperties().get("tilewidth", Integer.class); int tileHeight = tileset.getProperties().get("tileheight", Integer.class); int margin = tileset.getProperties().get("margin", Integer.class); int spacing = tileset.getProperties().get("spacing", Integer.class); this.firstgid = firstgid; image = ImageIO.read(baseDir.child(tileset.getProperties().get("imagesource", String.class)).read()); imageTilePositions = new IntMap<Vector2>(); // fill the tile regions int x, y, tile = 0; numRows = 0; numCols = 0; int stopWidth = image.getWidth() - tileWidth; int stopHeight = image.getHeight() - tileHeight; for (y = margin; y <= stopHeight; y += tileHeight + spacing) { for (x = margin; x <= stopWidth; x += tileWidth + spacing) { if (y == margin) numCols++; imageTilePositions.put(tile, new Vector2(x, y)); tile++; } numRows++; } numTiles = numRows * numCols; }
private void init (TiledMap map) { String axis = map.getProperties().get("staggeraxis", String.class); if (axis != null) { if (axis.equals("x")) { String index = map.getProperties().get("staggerindex", String.class); if (index != null) { if (index.equals("even")) { Integer length = map.getProperties().get("hexsidelength", Integer.class); if (length != null) { hexSideLength = length.intValue(); } else { if (staggerAxisX) { length = map.getProperties().get("tilewidth", Integer.class); if (length != null) { hexSideLength = 0.5f * length.intValue(); length = map.getProperties().get("tileheight", Integer.class); if (length != null) { hexSideLength = 0.5f * length.intValue();
private void init (TiledMap map) { String axis = map.getProperties().get("staggeraxis", String.class); if (axis != null) { if (axis.equals("x")) { String index = map.getProperties().get("staggerindex", String.class); if (index != null) { if (index.equals("even")) { Integer length = map.getProperties().get("hexsidelength", Integer.class); if (length != null) { hexSideLength = length.intValue(); } else { if (staggerAxisX) { length = map.getProperties().get("tilewidth", Integer.class); if (length != null) { hexSideLength = 0.5f * length.intValue(); length = map.getProperties().get("tileheight", Integer.class); if (length != null) { hexSideLength = 0.5f * length.intValue();
private String tilesetNameFromTileId (TiledMap map, int tileid) { String name = ""; if (tileid == 0) { return ""; } for (TiledMapTileSet tileset : map.getTileSets()) { int firstgid = tileset.getProperties().get("firstgid", -1, Integer.class); if (firstgid == -1) continue; // skip this tileset if (tileid >= firstgid) { name = tileset.getName(); } else { return name; } } return name; }
private String tilesetNameFromTileId (TiledMap map, int tileid) { String name = ""; if (tileid == 0) { return ""; } for (TiledMapTileSet tileset : map.getTileSets()) { int firstgid = tileset.getProperties().get("firstgid", -1, Integer.class); if (firstgid == -1) continue; // skip this tileset if (tileid >= firstgid) { name = tileset.getName(); } else { return name; } } return name; }
String mapCustomValue = map.getProperties().get(MAP_PROPERTY_NAME, String.class); Gdx.app.log("TiledMapAssetManagerTest", "Property : " + MAP_PROPERTY_NAME + ", Value : " + mapCustomValue); if (!MAP_PROPERTY_VALUE.equals(mapCustomValue)) { boolean boolCustomValue = map.getProperties().get(BOOL_PROPERTY_NAME, Boolean.class); Gdx.app.log("TiledMapAssetManagerTest", "Property : " + BOOL_PROPERTY_NAME + ", Value : " + boolCustomValue); if (boolCustomValue != BOOL_PROPERTY_VALUE) { int intCustomValue = map.getProperties().get(INT_PROPERTY_NAME, Integer.class); Gdx.app.log("TiledMapAssetManagerTest", "Property : " + INT_PROPERTY_NAME + ", Value : " + intCustomValue); if (intCustomValue != INT_PROPERTY_VALUE) { float floatCustomValue = map.getProperties().get(FLOAT_PROPERTY_NAME, Float.class); Gdx.app.log("TiledMapAssetManagerTest", "Property : " + FLOAT_PROPERTY_NAME + ", Value : " + floatCustomValue); if (floatCustomValue != FLOAT_PROPERTY_VALUE) { String tilesetCustomValue = tileset.getProperties().get(TILESET_PROPERTY_NAME, String.class); if (!TILESET_PROPERTY_VALUE.equals(tilesetCustomValue)) { throw new RuntimeException("Failed to get tileset properties"); String tileCustomValue = tile.getProperties().get(TILE_PROPERTY_NAME, String.class); if (!TILE_PROPERTY_VALUE.equals(tileCustomValue)) { throw new RuntimeException("Failed to get tile properties"); String layerCustomValue = layer.getProperties().get(LAYER_PROPERTY_NAME, String.class); if (!LAYER_PROPERTY_VALUE.equals(layerCustomValue)) { throw new RuntimeException("Failed to get layer properties");
private void stripUnusedTiles () { int mapWidth = map.getProperties().get("width", Integer.class); int mapHeight = map.getProperties().get("height", Integer.class); int numlayers = map.getLayers().getCount(); int bucketSize = mapWidth * mapHeight * numlayers; Iterator<MapLayer> it = map.getLayers().iterator(); while (it.hasNext()) { MapLayer layer = it.next(); // some layers can be plain MapLayer instances (ie. object groups), just ignore them if (layer instanceof TiledMapTileLayer) { TiledMapTileLayer tlayer = (TiledMapTileLayer)layer; for (int y = 0; y < mapHeight; ++y) { for (int x = 0; x < mapWidth; ++x) { if (tlayer.getCell(x, y) != null) { TiledMapTile tile = tlayer.getCell(x, y).getTile(); if (tile instanceof AnimatedTiledMapTile) { AnimatedTiledMapTile aTile = (AnimatedTiledMapTile)tile; for (StaticTiledMapTile t : aTile.getFrameTiles()) { addTile(t, bucketSize); } } // Adds non-animated tiles and the base animated tile addTile(tile, bucketSize); } } } } } }
private void stripUnusedTiles () { int mapWidth = map.getProperties().get("width", Integer.class); int mapHeight = map.getProperties().get("height", Integer.class); int numlayers = map.getLayers().getCount(); int bucketSize = mapWidth * mapHeight * numlayers; Iterator<MapLayer> it = map.getLayers().iterator(); while (it.hasNext()) { MapLayer layer = it.next(); // some layers can be plain MapLayer instances (ie. object groups), just ignore them if (layer instanceof TiledMapTileLayer) { TiledMapTileLayer tlayer = (TiledMapTileLayer)layer; for (int y = 0; y < mapHeight; ++y) { for (int x = 0; x < mapWidth; ++x) { if (tlayer.getCell(x, y) != null) { TiledMapTile tile = tlayer.getCell(x, y).getTile(); if (tile instanceof AnimatedTiledMapTile) { AnimatedTiledMapTile aTile = (AnimatedTiledMapTile)tile; for (StaticTiledMapTile t : aTile.getFrameTiles()) { addTile(t, bucketSize); } } // Adds non-animated tiles and the base animated tile addTile(tile, bucketSize); } } } } } }
int width = element.getIntAttribute("width", 0); int height = element.getIntAttribute("height", 0); int tileWidth = map.getProperties().get("tilewidth", Integer.class); int tileHeight = map.getProperties().get("tileheight", Integer.class); TiledMapTileLayer layer = new TiledMapTileLayer(width, height, tileWidth, tileHeight);
int width = element.getIntAttribute("width", 0); int height = element.getIntAttribute("height", 0); int tileWidth = map.getProperties().get("tilewidth", Integer.class); int tileHeight = map.getProperties().get("tileheight", Integer.class); TiledMapTileLayer layer = new TiledMapTileLayer(width, height, tileWidth, tileHeight);
if (name.equals("TileSheet")) { currentTileSet = tilesets.getTileSet(currentChild.getAttribute("Ref")); firstgid = currentTileSet.getProperties().get("firstgid", Integer.class); } else if (name.equals("Null")) { x += currentChild.getIntAttribute("Count"); if (frameName.equals("TileSheet")) { currentTileSet = tilesets.getTileSet(frame.getAttribute("Ref")); firstgid = currentTileSet.getProperties().get("firstgid", Integer.class); } else if (frameName.equals("Static")) { frameTiles.add((StaticTiledMapTile)currentTileSet.getTile(firstgid + frame.getIntAttribute("Index")));
if (name.equals("TileSheet")) { currentTileSet = tilesets.getTileSet(currentChild.getAttribute("Ref")); firstgid = currentTileSet.getProperties().get("firstgid", Integer.class); } else if (name.equals("Null")) { x += currentChild.getIntAttribute("Count"); if (frameName.equals("TileSheet")) { currentTileSet = tilesets.getTileSet(frame.getAttribute("Ref")); firstgid = currentTileSet.getProperties().get("firstgid", Integer.class); } else if (frameName.equals("Static")) { frameTiles.add((StaticTiledMapTile)currentTileSet.getTile(firstgid + frame.getIntAttribute("Index")));
String atlasFilePath = map.getProperties().get("atlas", String.class); if (atlasFilePath == null) { FileHandle atlasFile = tmxFile.sibling(tmxFile.nameWithoutExtension() + ".atlas");