List of usage examples for com.badlogic.gdx.maps.tiled TiledMapTile getId
public int getId();
From source file:com.agateau.pixelwheels.map.Track.java
License:Open Source License
private Material[] computeMaterialForTileId() { TiledMapTileSet tileSet = mMap.getTileSets().getTileSet(0); int maxId = 0; for (TiledMapTile tile : tileSet) { maxId = Math.max(maxId, tile.getId()); }//from www . j a v a 2 s . c o m Material[] array = new Material[maxId + 1]; for (int id = 0; id < array.length; ++id) { TiledMapTile tile = tileSet.getTile(id); array[id] = MapUtils.getTileMaterial(tile); } return array; }
From source file:com.agateau.pixelwheels.map.Track.java
License:Open Source License
private void findSpecialTileIds() { TiledMapTileSet tileSet = mMap.getTileSets().getTileSet(0); for (TiledMapTile tile : tileSet) { MapProperties properties = tile.getProperties(); if (MapUtils.getBooleanProperty(properties, "start", false)) { mStartTileId = tile.getId(); }/*from www. jav a2 s . co m*/ } Assert.check(mStartTileId != -1, "No start id"); }
From source file:com.agateau.pixelwheels.map.Track.java
License:Open Source License
public Material getMaterialAt(float x, float y) { TiledMapTile tile = getTopTileAt(mBackgroundLayers, x, y); if (tile == null) { return Material.ROAD; }/* ww w. j a v a2s . c o m*/ return mMaterialForTileId[tile.getId()]; }
From source file:com.betmansmall.game.gameLogic.mapLoader.MapLoader.java
License:Apache License
/** Loads the specified tileset data, adding it to the collection of the specified map, given the XML element, the tmxFile and * an {@link ImageResolver} used to retrieve the tileset Textures. * * <p>/* w w w . j a v a2s . co m*/ * Default tileset's property keys that are loaded by default are: * </p> * * <ul> * <li><em>firstgid</em>, (int, defaults to 1) the first valid global id used for tile numbering</li> * <li><em>imagesource</em>, (String, defaults to empty string) the tileset source image filename</li> * <li><em>imagewidth</em>, (int, defaults to 0) the tileset source image width</li> * <li><em>imageheight</em>, (int, defaults to 0) the tileset source image height</li> * <li><em>tilewidth</em>, (int, defaults to 0) the tile width</li> * <li><em>tileheight</em>, (int, defaults to 0) the tile height</li> * <li><em>margin</em>, (int, defaults to 0) the tileset margin</li> * <li><em>spacing</em>, (int, defaults to 0) the tileset spacing</li> * </ul> * * <p> * The values are extracted from the specified Tmx file, if a value can't be found then the default is used. * </p> * @param map the Map whose tilesets collection will be populated * @param element the XML element identifying the tileset to load * @param tmxFile the Filehandle of the tmx file * @param imageResolver the {@link ImageResolver} */ protected void loadTileSet(TiledMap map, Element element, FileHandle tmxFile, ImageResolver imageResolver) { 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); int offsetX = 0; int offsetY = 0; String imageSource = ""; int imageWidth = 0, imageHeight = 0; FileHandle image = null; 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); Element offset = element.getChildByName("tileoffset"); if (offset != null) { offsetX = offset.getIntAttribute("x", 0); offsetY = offset.getIntAttribute("y", 0); } Element imageElement = element.getChildByName("image"); if (imageElement != null) { imageSource = imageElement.getAttribute("source"); imageWidth = imageElement.getIntAttribute("width", 0); imageHeight = imageElement.getIntAttribute("height", 0); image = getRelativeFileHandle(tsx, imageSource); } } catch (IOException e) { throw new GdxRuntimeException("Error parsing external tileset."); } } else { Element offset = element.getChildByName("tileoffset"); if (offset != null) { offsetX = offset.getIntAttribute("x", 0); offsetY = offset.getIntAttribute("y", 0); } Element imageElement = element.getChildByName("image"); if (imageElement != null) { imageSource = imageElement.getAttribute("source"); imageWidth = imageElement.getIntAttribute("width", 0); imageHeight = imageElement.getIntAttribute("height", 0); image = getRelativeFileHandle(tmxFile, imageSource); } } TiledMapTileSet tileset = new TiledMapTileSet(); tileset.setName(name); tileset.getProperties().put("firstgid", firstgid); if (image != null) { TextureRegion texture = imageResolver.getImage(image.path()); MapProperties props = tileset.getProperties(); 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); int stopWidth = texture.getRegionWidth() - tilewidth; int stopHeight = texture.getRegionHeight() - tileheight; int id = firstgid; for (int y = margin; y <= stopHeight; y += tileheight + spacing) { for (int x = margin; x <= stopWidth; x += tilewidth + spacing) { TextureRegion tileRegion = new TextureRegion(texture, x, y, tilewidth, tileheight); TiledMapTile tile = new StaticTiledMapTile(tileRegion); tile.setId(id); tile.setOffsetX(offsetX); tile.setOffsetY(flipY ? -offsetY : offsetY); tileset.putTile(id++, tile); } } } else { Array<Element> tileElements = element.getChildrenByName("tile"); for (Element tileElement : tileElements) { Element imageElement = tileElement.getChildByName("image"); if (imageElement != null) { imageSource = imageElement.getAttribute("source"); imageWidth = imageElement.getIntAttribute("width", 0); imageHeight = imageElement.getIntAttribute("height", 0); image = getRelativeFileHandle(tmxFile, imageSource); } TextureRegion texture = imageResolver.getImage(image.path()); TiledMapTile tile = new StaticTiledMapTile(texture); tile.setId(firstgid + tileElement.getIntAttribute("id")); tile.setOffsetX(offsetX); tile.setOffsetY(flipY ? -offsetY : offsetY); tileset.putTile(tile.getId(), tile); } } Array<Element> tileElements = element.getChildrenByName("tile"); Array<AnimatedTiledMapTile> animatedTiles = new Array<AnimatedTiledMapTile>(); for (Element tileElement : tileElements) { int localtid = tileElement.getIntAttribute("id", 0); TiledMapTile tile = tileset.getTile(firstgid + localtid); if (tile != null) { Element animationElement = tileElement.getChildByName("animation"); if (animationElement != null) { Array<StaticTiledMapTile> staticTiles = new Array<StaticTiledMapTile>(); IntArray intervals = new IntArray(); for (Element frameElement : animationElement.getChildrenByName("frame")) { staticTiles.add((StaticTiledMapTile) tileset .getTile(firstgid + frameElement.getIntAttribute("tileid"))); intervals.add(frameElement.getIntAttribute("duration")); } AnimatedTiledMapTile animatedTile = new AnimatedTiledMapTile(intervals, staticTiles); animatedTile.setId(tile.getId()); animatedTiles.add(animatedTile); tile = animatedTile; } 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); } } } for (AnimatedTiledMapTile tile : animatedTiles) { tileset.putTile(tile.getId(), tile); } Element properties = element.getChildByName("properties"); if (properties != null) { loadProperties(tileset.getProperties(), properties); } map.getTileSets().addTileSet(tileset); } }
From source file:com.skettios.loader.TmxMapLoaderFixed.java
License:Apache License
/** * Loads the specified tileset data, adding it to the collection of the specified map, given the XML element, the tmxFile and * an {@link ImageResolver} used to retrieve the tileset Textures. * <p/>/*from w w w .j a v a 2s . com*/ * <p> * Default tileset's property keys that are loaded by default are: * </p> * <p/> * <ul> * <li><em>firstgid</em>, (int, defaults to 1) the first valid global id used for tile numbering</li> * <li><em>imagesource</em>, (String, defaults to empty string) the tileset source image filename</li> * <li><em>imagewidth</em>, (int, defaults to 0) the tileset source image width</li> * <li><em>imageheight</em>, (int, defaults to 0) the tileset source image height</li> * <li><em>tilewidth</em>, (int, defaults to 0) the tile width</li> * <li><em>tileheight</em>, (int, defaults to 0) the tile height</li> * <li><em>margin</em>, (int, defaults to 0) the tileset margin</li> * <li><em>spacing</em>, (int, defaults to 0) the tileset spacing</li> * </ul> * <p/> * <p> * The values are extracted from the specified Tmx file, if a value can't be found then the default is used. * </p> * * @param map the Map whose tilesets collection will be populated * @param element the XML element identifying the tileset to load * @param tmxFile the Filehandle of the tmx file * @param imageResolver the {@link ImageResolver} */ protected void loadTileSet(TiledMap map, Element element, FileHandle tmxFile, ImageResolver imageResolver) { 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); int offsetX = 0; int offsetY = 0; String imageSource = ""; int imageWidth = 0, imageHeight = 0; FileHandle image = null; if (source != null) { FileHandle tsx = getRelativeFileHandleFixed(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); Element offset = element.getChildByName("tileoffset"); if (offset != null) { offsetX = offset.getIntAttribute("x", 0); offsetY = offset.getIntAttribute("y", 0); } Element imageElement = element.getChildByName("image"); if (imageElement != null) { imageSource = imageElement.getAttribute("source"); imageWidth = imageElement.getIntAttribute("width", 0); imageHeight = imageElement.getIntAttribute("height", 0); image = getRelativeFileHandleFixed(tsx, imageSource); } } catch (IOException e) { throw new GdxRuntimeException("Error parsing external tileset."); } } else { Element offset = element.getChildByName("tileoffset"); if (offset != null) { offsetX = offset.getIntAttribute("x", 0); offsetY = offset.getIntAttribute("y", 0); } Element imageElement = element.getChildByName("image"); if (imageElement != null) { imageSource = imageElement.getAttribute("source"); imageWidth = imageElement.getIntAttribute("width", 0); imageHeight = imageElement.getIntAttribute("height", 0); image = getRelativeFileHandleFixed(tmxFile, imageSource); } } TiledMapTileSet tileset = new TiledMapTileSet(); tileset.setName(name); tileset.getProperties().put("firstgid", firstgid); if (image != null) { TextureRegion texture = imageResolver.getImage(image.path()); MapProperties props = tileset.getProperties(); 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); int stopWidth = texture.getRegionWidth() - tilewidth; int stopHeight = texture.getRegionHeight() - tileheight; int id = firstgid; for (int y = margin; y <= stopHeight; y += tileheight + spacing) { for (int x = margin; x <= stopWidth; x += tilewidth + spacing) { TextureRegion tileRegion = new TextureRegion(texture, x, y, tilewidth, tileheight); TiledMapTile tile = new StaticTiledMapTile(tileRegion); tile.setId(id); tile.setOffsetX(offsetX); tile.setOffsetY(-offsetY); tileset.putTile(id++, tile); } } } else { Array<Element> tileElements = element.getChildrenByName("tile"); for (Element tileElement : tileElements) { Element imageElement = tileElement.getChildByName("image"); if (imageElement != null) { imageSource = imageElement.getAttribute("source"); imageWidth = imageElement.getIntAttribute("width", 0); imageHeight = imageElement.getIntAttribute("height", 0); image = getRelativeFileHandleFixed(tmxFile, imageSource); } TextureRegion texture = imageResolver.getImage(image.path()); TiledMapTile tile = new StaticTiledMapTile(texture); tile.setId(firstgid + tileElement.getIntAttribute("id")); tile.setOffsetX(offsetX); tile.setOffsetY(-offsetY); tileset.putTile(tile.getId(), tile); } } Array<Element> tileElements = element.getChildrenByName("tile"); Array<AnimatedTiledMapTile> animatedTiles = new Array<AnimatedTiledMapTile>(); for (Element tileElement : tileElements) { int localtid = tileElement.getIntAttribute("id", 0); TiledMapTile tile = tileset.getTile(firstgid + localtid); if (tile != null) { Element animationElement = tileElement.getChildByName("animation"); if (animationElement != null) { Array<StaticTiledMapTile> staticTiles = new Array<StaticTiledMapTile>(); IntArray intervals = new IntArray(); for (Element frameElement : animationElement.getChildrenByName("frame")) { staticTiles.add((StaticTiledMapTile) tileset .getTile(firstgid + frameElement.getIntAttribute("tileid"))); intervals.add(frameElement.getIntAttribute("duration")); } AnimatedTiledMapTile animatedTile = new AnimatedTiledMapTile(intervals, staticTiles); animatedTile.setId(tile.getId()); animatedTiles.add(animatedTile); tile = animatedTile; } 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); } } } for (AnimatedTiledMapTile tile : animatedTiles) { tileset.putTile(tile.getId(), tile); } Element properties = element.getChildByName("properties"); if (properties != null) { loadProperties(tileset.getProperties(), properties); } map.getTileSets().addTileSet(tileset); } }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.maps.MapUtils.java
License:Apache License
/** @see #readableHierarchy(com.badlogic.gdx.maps.Map, int) */ public static String readableHierarchy(TiledMapTile tile, int indent) { String hierarchy = ""; for (int i = 0; i < indent; i++) hierarchy += '\t'; hierarchy += ClassReflection.getSimpleName(tile.getClass()) + " (ID: " + tile.getId() + ", offset: " + tile.getOffsetX() + 'x' + tile.getOffsetY() + ", BlendMode: " + tile.getBlendMode() + ")\n"; hierarchy += readableHierarchy(tile.getProperties(), indent + 1); return hierarchy; }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.maps.TmxMapWriter.java
License:Apache License
/** @param layer the {@link TiledMapTileLayer} to write in TMX format * @param format the {@link Format} to use * @return this {@link TmxMapWriter} */ public TmxMapWriter tmx(TiledMapTileLayer layer, Format format) throws IOException { element("layer"); attribute("name", layer.getName()); attribute("width", layer.getWidth()); attribute("height", layer.getHeight()); attribute("visible", layer.isVisible() ? 1 : 0); attribute("opacity", layer.getOpacity()); tmx(layer.getProperties());//from www . ja v a 2 s . com element("data"); if (format == XML) { attribute("encoding", "xml"); for (int y = layer.getHeight() - 1; y > -1; y--) for (int x = 0; x < layer.getWidth(); x++) { Cell cell = layer.getCell(x, y); if (cell != null) { TiledMapTile tile = cell.getTile(); if (tile == null) continue; element("tile"); attribute("gid", tile.getId()); pop(); } } } else if (format == CSV) { attribute("encoding", "csv"); StringBuilder csv = new StringBuilder(); for (int y = layer.getHeight() - 1; y > -1; y--) { for (int x = 0; x < layer.getWidth(); x++) { Cell cell = layer.getCell(x, y); TiledMapTile tile = cell != null ? cell.getTile() : null; csv.append(tile != null ? tile.getId() : 0); if (x + 1 < layer.getWidth() || y - 1 > -1) csv.append(','); } csv.append('\n'); } append('\n').append(csv); } else if (format == Base64 || format == Base64Zlib || format == Base64Gzip) { attribute("encoding", "base64"); if (format == Base64Zlib) attribute("compression", "zlib"); else if (format == Base64Gzip) attribute("compression", "gzip"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream out = format == Base64Zlib ? new DeflaterOutputStream(baos) : format == Base64Gzip ? new GZIPOutputStream(baos) : baos; final short LAST_BYTE = 0xFF; for (int y = layer.getHeight() - 1; y > -1; y--) for (int x = 0; x < layer.getWidth(); x++) { Cell cell = layer.getCell(x, y); TiledMapTile tile = cell != null ? cell.getTile() : null; int gid = tile != null ? tile.getId() : 0; out.write(gid & LAST_BYTE); out.write(gid >> 8 & LAST_BYTE); out.write(gid >> 16 & LAST_BYTE); out.write(gid >> 24 & LAST_BYTE); } if (out instanceof DeflaterOutputStream) ((DeflaterOutputStream) out).finish(); out.close(); baos.close(); append('\n').append(String.valueOf(Base64Coder.encode(baos.toByteArray()))).append('\n'); } pop(); pop(); return this; }
From source file:de.fhkoeln.game.utils.libgdx.maps.MapUtils.java
License:Apache License
/** @see #readableHierarchy(com.badlogic.gdx.maps.Map, int) */ public static String readableHierarchy(TiledMapTile tile, int indent) { String hierarchy = ""; for (int i = 0; i < indent; i++) hierarchy += '\t'; hierarchy += tile.getClass().getSimpleName() + " (ID: " + tile.getId() + ", offset: " + tile.getOffsetX() + 'x' + tile.getOffsetY() + ", BlendMode: " + tile.getBlendMode() + ")\n"; hierarchy += readableHierarchy(tile.getProperties(), indent + 1); return hierarchy; }
From source file:de.fhkoeln.game.utils.libgdx.maps.TmxMapWriter.java
License:Apache License
/** @param layer the {@link com.badlogic.gdx.maps.tiled.TiledMapTileLayer} to write in TMX format * @param format the {@link de.fhkoeln.game.utils.libgdx.maps.TmxMapWriter.Format} to use * @return this {@link de.fhkoeln.game.utils.libgdx.maps.TmxMapWriter} */ public TmxMapWriter tmx(TiledMapTileLayer layer, Format format) throws IOException { element("layer"); attribute("name", layer.getName()); attribute("width", layer.getWidth()); attribute("height", layer.getHeight()); attribute("visible", layer.isVisible() ? 1 : 0); attribute("opacity", layer.getOpacity()); tmx(layer.getProperties());//w w w . j a va 2s.c o m element("data"); if (format == Format.XML) { attribute("encoding", "xml"); for (int y = layer.getHeight() - 1; y > -1; y--) for (int x = 0; x < layer.getWidth(); x++) { Cell cell = layer.getCell(x, y); if (cell != null) { TiledMapTile tile = cell.getTile(); if (tile == null) continue; element("tile"); attribute("gid", tile.getId()); pop(); } } } else if (format == Format.CSV) { attribute("encoding", "csv"); StringBuilder csv = new StringBuilder(); for (int y = layer.getHeight() - 1; y > -1; y--) { for (int x = 0; x < layer.getWidth(); x++) { Cell cell = layer.getCell(x, y); TiledMapTile tile = cell != null ? cell.getTile() : null; csv.append(tile != null ? tile.getId() : 0); if (x + 1 < layer.getWidth() || y - 1 > -1) csv.append(','); } csv.append('\n'); } append('\n').append(csv); } else if (format == Format.Base64 || format == Format.Base64Zlib || format == Format.Base64Gzip) { attribute("encoding", "base64"); if (format == Format.Base64Zlib) attribute("compression", "zlib"); else if (format == Format.Base64Gzip) attribute("compression", "gzip"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream out = format == Format.Base64Zlib ? new DeflaterOutputStream(baos) : format == Format.Base64Gzip ? new GZIPOutputStream(baos) : baos; final short LAST_BYTE = 0xFF; for (int y = layer.getHeight() - 1; y > -1; y--) for (int x = 0; x < layer.getWidth(); x++) { Cell cell = layer.getCell(x, y); TiledMapTile tile = cell != null ? cell.getTile() : null; int gid = tile != null ? tile.getId() : 0; out.write(gid & LAST_BYTE); out.write(gid >> 8 & LAST_BYTE); out.write(gid >> 16 & LAST_BYTE); out.write(gid >> 24 & LAST_BYTE); } if (out instanceof DeflaterOutputStream) ((DeflaterOutputStream) out).finish(); out.close(); baos.close(); append('\n').append(String.valueOf(Base64Coder.encode(baos.toByteArray()))).append('\n'); } pop(); pop(); return this; }
From source file:me.boxcubed.main.desktop.server.ServerTiledMapLoader.java
License:Apache License
/** Loads the specified tileset data, adding it to the collection of the specified map, given the XML element, the tmxFile and * an {@link ImageResolver} used to retrieve the tileset Textures. * /*from w w w .ja va 2s. c o m*/ * <p> * Default tileset's property keys that are loaded by default are: * </p> * * <ul> * <li><em>firstgid</em>, (int, defaults to 1) the first valid global id used for tile numbering</li> * <li><em>imagesource</em>, (String, defaults to empty string) the tileset source image filename</li> * <li><em>imagewidth</em>, (int, defaults to 0) the tileset source image width</li> * <li><em>imageheight</em>, (int, defaults to 0) the tileset source image height</li> * <li><em>tilewidth</em>, (int, defaults to 0) the tile width</li> * <li><em>tileheight</em>, (int, defaults to 0) the tile height</li> * <li><em>margin</em>, (int, defaults to 0) the tileset margin</li> * <li><em>spacing</em>, (int, defaults to 0) the tileset spacing</li> * </ul> * * <p> * The values are extracted from the specified Tmx file, if a value can't be found then the default is used. * </p> * @param map the Map whose tilesets collection will be populated * @param element the XML element identifying the tileset to load * @param tmxFile the Filehandle of the tmx file * @param imageResolver the {@link ImageResolver} */ @SuppressWarnings("unused") protected void loadTileSet(TiledMap map, Element element, FileHandle tmxFile, ImageResolver imageResolver) { 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); int offsetX = 0; int offsetY = 0; String imageSource = ""; int imageWidth = 0, imageHeight = 0; FileHandle image = null; 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); Element offset = element.getChildByName("tileoffset"); if (offset != null) { offsetX = offset.getIntAttribute("x", 0); offsetY = offset.getIntAttribute("y", 0); } Element imageElement = element.getChildByName("image"); if (imageElement != null) { imageSource = imageElement.getAttribute("source"); imageWidth = imageElement.getIntAttribute("width", 0); imageHeight = imageElement.getIntAttribute("height", 0); image = getRelativeFileHandle(tsx, imageSource); } } catch (IOException e) { throw new GdxRuntimeException("Error parsing external tileset."); } } else { Element offset = element.getChildByName("tileoffset"); if (offset != null) { offsetX = offset.getIntAttribute("x", 0); offsetY = offset.getIntAttribute("y", 0); } Element imageElement = element.getChildByName("image"); if (imageElement != null) { imageSource = imageElement.getAttribute("source"); imageWidth = imageElement.getIntAttribute("width", 0); imageHeight = imageElement.getIntAttribute("height", 0); image = getRelativeFileHandle(tmxFile, imageSource); } } TiledMapTileSet tileset = new TiledMapTileSet(); tileset.setName(name); tileset.getProperties().put("firstgid", firstgid); if (false) { } else { Array<Element> tileElements = element.getChildrenByName("tile"); for (Element tileElement : tileElements) { Element imageElement = tileElement.getChildByName("image"); if (imageElement != null) { imageSource = imageElement.getAttribute("source"); imageWidth = imageElement.getIntAttribute("width", 0); imageHeight = imageElement.getIntAttribute("height", 0); image = getRelativeFileHandle(tmxFile, imageSource); } TextureRegion texture = imageResolver.getImage(image.path()); TiledMapTile tile = new StaticTiledMapTile(texture); tile.setId(firstgid + tileElement.getIntAttribute("id")); tile.setOffsetX(offsetX); tile.setOffsetY(flipY ? -offsetY : offsetY); tileset.putTile(tile.getId(), tile); } } Array<Element> tileElements = element.getChildrenByName("tile"); Array<AnimatedTiledMapTile> animatedTiles = new Array<AnimatedTiledMapTile>(); for (Element tileElement : tileElements) { int localtid = tileElement.getIntAttribute("id", 0); TiledMapTile tile = tileset.getTile(firstgid + localtid); if (tile != null) { Element animationElement = tileElement.getChildByName("animation"); if (animationElement != null) { Array<StaticTiledMapTile> staticTiles = new Array<StaticTiledMapTile>(); IntArray intervals = new IntArray(); for (Element frameElement : animationElement.getChildrenByName("frame")) { staticTiles.add((StaticTiledMapTile) tileset .getTile(firstgid + frameElement.getIntAttribute("tileid"))); intervals.add(frameElement.getIntAttribute("duration")); } AnimatedTiledMapTile animatedTile = new AnimatedTiledMapTile(intervals, staticTiles); animatedTile.setId(tile.getId()); animatedTiles.add(animatedTile); tile = animatedTile; } 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); } } } for (AnimatedTiledMapTile tile : animatedTiles) { tileset.putTile(tile.getId(), tile); } Element properties = element.getChildByName("properties"); if (properties != null) { loadProperties(tileset.getProperties(), properties); } map.getTileSets().addTileSet(tileset); } }