List of usage examples for com.badlogic.gdx.maps.tiled.tiles StaticTiledMapTile getProperties
@Override
public MapProperties getProperties()
From source file:com.stercore.code.net.dermetfan.utils.libgdx.maps.TileAnimator.java
License:Apache License
/** sorts the frames of the animation by their orderedKey value if it exists * @param animations the animations to sort * @param orderedKey the key of the frame property * @return the animations with sorted frames * @see #sortFrames(Array, String) */ public static ObjectMap<String, Array<StaticTiledMapTile>> sortFrames( ObjectMap<String, Array<StaticTiledMapTile>> animations, String orderedKey) { Entry<String, Array<StaticTiledMapTile>> entry; Entries<String, Array<StaticTiledMapTile>> entries = animations.entries(); while (entries.hasNext) { entry = entries.next();//from w w w . ja va 2 s. c o m for (StaticTiledMapTile entryTile : entry.value) if (entryTile.getProperties().containsKey(orderedKey)) { sortFrames(entry.value, orderedKey); break; } } return animations; }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.maps.TileAnimator.java
License:Apache License
/** sorts the frames by their orderedKey value * @param frames the frames to sort//from w w w . j a v a 2s .c o m * @param orderedKey the key of the ordered/frame property */ public static void sortFrames(Array<StaticTiledMapTile> frames, final String orderedKey) { frames.sort(new Comparator<StaticTiledMapTile>() { @Override public int compare(StaticTiledMapTile tile1, StaticTiledMapTile tile2) { int tile1Frame = getProperty(tile1.getProperties(), orderedKey, -1), tile2Frame = getProperty(tile2.getProperties(), orderedKey, -1); return tile1Frame < tile2Frame ? -1 : tile1Frame > tile2Frame ? 1 : 0; } }); }
From source file:de.bitowl.advent.game2.MyAtlasTmxMapLoader.java
License:Apache License
protected void loadTileset(TiledMap map, Element element, FileHandle tmxFile, AtlasResolver resolver, AtlasTiledMapLoaderParameters parameter) { if (element.getName().equals("tileset")) { String name = element.get("name", null); int firstgid = element.getIntAttribute("firstgid", 1); int tilewidth = element.getIntAttribute("tilewidth", 0); int tileheight = element.getIntAttribute("tileheight", 0); int spacing = element.getIntAttribute("spacing", 0); int margin = element.getIntAttribute("margin", 0); String source = element.getAttribute("source", null); String imageSource = ""; int imageWidth = 0, imageHeight = 0; FileHandle image = null;//from w w w .ja v a 2 s .c o m if (source != null) { FileHandle tsx = getRelativeFileHandle(tmxFile, source); try { element = xml.parse(tsx); name = element.get("name", null); tilewidth = element.getIntAttribute("tilewidth", 0); tileheight = element.getIntAttribute("tileheight", 0); spacing = element.getIntAttribute("spacing", 0); margin = element.getIntAttribute("margin", 0); imageSource = element.getChildByName("image").getAttribute("source"); imageWidth = element.getChildByName("image").getIntAttribute("width", 0); imageHeight = element.getChildByName("image").getIntAttribute("height", 0); } catch (IOException e) { throw new GdxRuntimeException("Error parsing external tileset."); } } else { imageSource = element.getChildByName("image").getAttribute("source"); imageWidth = element.getChildByName("image").getIntAttribute("width", 0); imageHeight = element.getChildByName("image").getIntAttribute("height", 0); } if (!map.getProperties().containsKey("atlas")) { throw new GdxRuntimeException("The map is missing the 'atlas' property"); } // get the TextureAtlas for this tileset FileHandle atlasHandle = getRelativeFileHandle(tmxFile, map.getProperties().get("atlas", String.class)); atlasHandle = resolve(atlasHandle.path()); TextureAtlas atlas = resolver.getAtlas(atlasHandle.path()); //String regionsName = atlasHandle.nameWithoutExtension(); String regionsName = name; if (parameter != null && parameter.forceTextureFilters) { for (Texture texture : atlas.getTextures()) { trackedTextures.add(texture); } } TiledMapTileSet tileset = new TiledMapTileSet(); MapProperties props = tileset.getProperties(); tileset.setName(name); props.put("firstgid", firstgid); props.put("imagesource", imageSource); props.put("imagewidth", imageWidth); props.put("imageheight", imageHeight); props.put("tilewidth", tilewidth); props.put("tileheight", tileheight); props.put("margin", margin); props.put("spacing", spacing); Array<AtlasRegion> regions = atlas.findRegions(regionsName); System.out.println(regions.size); for (AtlasRegion region : regions) { // handle unused tile ids if (region != null) { StaticTiledMapTile tile = new StaticTiledMapTile(region); if (!yUp) { region.flip(false, true); } int tileid = firstgid + region.index; tile.setId(tileid); tileset.putTile(tileid, tile); System.out.println("put tile " + tileid); } } Array<Element> tileElements = element.getChildrenByName("tile"); for (Element tileElement : tileElements) { int localtid = tileElement.getIntAttribute("id", 0); TiledMapTile tile = tileset.getTile(firstgid + localtid); if (tile != null) { String terrain = tileElement.getAttribute("terrain", null); if (terrain != null) { tile.getProperties().put("terrain", terrain); } String probability = tileElement.getAttribute("probability", null); if (probability != null) { tile.getProperties().put("probability", probability); } Element properties = tileElement.getChildByName("properties"); if (properties != null) { loadProperties(tile.getProperties(), properties); } } } Element properties = element.getChildByName("properties"); if (properties != null) { loadProperties(tileset.getProperties(), properties); } System.out.println("add tileset to map: " + tileset.getName()); map.getTileSets().addTileSet(tileset); } }