}
// get the TextureAtlas for this tileset
FileHandle atlasHandle = getRelativeFileHandle(tmxFile, atlasFilePath);
atlasHandle = resolve(atlasHandle.path());
TextureAtlas atlas = resolver.getAtlas(atlasHandle.path());
String regionsName = atlasHandle.nameWithoutExtension();
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);
for (AtlasRegion region : atlas.findRegions(regionsName)) {
// handle unused tile ids
if (region != null) {
StaticTiledMapTile tile = new StaticTiledMapTile(region);
int tileid = firstgid + region.index;
tile.setId(tileid);
tile.setOffsetX(offsetX);
tile.setOffsetY(-offsetY);
tileset.putTile(tileid, tile);
}
}
for (Element tileElement : element.getChildrenByName("tile")) {
int tileid = firstgid + tileElement.getIntAttribute("id", 0);
TiledMapTile tile = tileset.getTile(tileid);
if (tile == null) {
Element imageElement = tileElement.getChildByName("image");
if (imageElement != null) {
// Is a tilemap with individual images.
String regionName = imageElement.getAttribute("source");
regionName = regionName.substring(0, regionName.lastIndexOf('.'));
AtlasRegion region = atlas.findRegion(regionName);
if (region == null) throw new GdxRuntimeException("Tileset region not found: " + regionName);
tile = new StaticTiledMapTile(region);
tile.setId(tileid);
tile.setOffsetX(offsetX);
tile.setOffsetY(-offsetY);