use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.
the class TideMapLoader method loadTileSheets.
/** Loads the tilesets
* @param root the root XML element
* @return a list of filenames for images containing tiles
* @throws IOException */
private Array<FileHandle> loadTileSheets(Element root, FileHandle tideFile) throws IOException {
Array<FileHandle> images = new Array<FileHandle>();
Element tilesheets = root.getChildByName("TileSheets");
for (Element tileset : tilesheets.getChildrenByName("TileSheet")) {
Element imageSource = tileset.getChildByName("ImageSource");
FileHandle image = getRelativeFileHandle(tideFile, imageSource.getText());
images.add(image);
}
return images;
}
use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.
the class TideMapLoader method load.
public TiledMap load(String fileName) {
try {
FileHandle tideFile = resolve(fileName);
root = xml.parse(tideFile);
ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>();
for (FileHandle textureFile : loadTileSheets(root, tideFile)) {
textures.put(textureFile.path(), new Texture(textureFile));
}
DirectImageResolver imageResolver = new DirectImageResolver(textures);
TiledMap map = loadMap(root, tideFile, imageResolver);
map.setOwnedResources(textures.values().toArray());
return map;
} catch (IOException e) {
throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
}
}
use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.
the class TmxMapLoader method loadTilesets.
/** Loads the tilesets
* @param root the root XML element
* @return a list of filenames for images containing tiles
* @throws IOException */
protected Array<FileHandle> loadTilesets(Element root, FileHandle tmxFile) throws IOException {
Array<FileHandle> images = new Array<FileHandle>();
for (Element tileset : root.getChildrenByName("tileset")) {
String source = tileset.getAttribute("source", null);
if (source != null) {
FileHandle tsxFile = getRelativeFileHandle(tmxFile, source);
tileset = xml.parse(tsxFile);
Element imageElement = tileset.getChildByName("image");
if (imageElement != null) {
String imageSource = tileset.getChildByName("image").getAttribute("source");
FileHandle image = getRelativeFileHandle(tsxFile, imageSource);
images.add(image);
} else {
for (Element tile : tileset.getChildrenByName("tile")) {
String imageSource = tile.getChildByName("image").getAttribute("source");
FileHandle image = getRelativeFileHandle(tsxFile, imageSource);
images.add(image);
}
}
} else {
Element imageElement = tileset.getChildByName("image");
if (imageElement != null) {
String imageSource = tileset.getChildByName("image").getAttribute("source");
FileHandle image = getRelativeFileHandle(tmxFile, imageSource);
images.add(image);
} else {
for (Element tile : tileset.getChildrenByName("tile")) {
String imageSource = tile.getChildByName("image").getAttribute("source");
FileHandle image = getRelativeFileHandle(tmxFile, imageSource);
images.add(image);
}
}
}
}
return images;
}
use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.
the class TmxMapLoader method loadImages.
/** Loads the images in image layers
* @param root the root XML element
* @return a list of filenames for images inside image layers
* @throws IOException */
protected Array<FileHandle> loadImages(Element root, FileHandle tmxFile) throws IOException {
Array<FileHandle> images = new Array<FileHandle>();
for (Element imageLayer : root.getChildrenByName("imagelayer")) {
Element image = imageLayer.getChildByName("image");
String source = image.getAttribute("source", null);
if (source != null) {
FileHandle handle = getRelativeFileHandle(tmxFile, source);
if (!images.contains(handle, false)) {
images.add(handle);
}
}
}
return images;
}
use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.
the class TmxMapLoader method load.
/** Loads the {@link TiledMap} from the given file. The file is resolved via the {@link FileHandleResolver} set in the
* constructor of this class. By default it will resolve to an internal file.
* @param fileName the filename
* @param parameters specifies whether to use y-up, generate mip maps etc.
* @return the TiledMap */
public TiledMap load(String fileName, TmxMapLoader.Parameters parameters) {
try {
this.convertObjectToTileSpace = parameters.convertObjectToTileSpace;
this.flipY = parameters.flipY;
FileHandle tmxFile = resolve(fileName);
root = xml.parse(tmxFile);
ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>();
Array<FileHandle> textureFiles = loadTilesets(root, tmxFile);
textureFiles.addAll(loadImages(root, tmxFile));
for (FileHandle textureFile : textureFiles) {
Texture texture = new Texture(textureFile, parameters.generateMipMaps);
texture.setFilter(parameters.textureMinFilter, parameters.textureMagFilter);
textures.put(textureFile.path(), texture);
}
DirectImageResolver imageResolver = new DirectImageResolver(textures);
TiledMap map = loadTilemap(root, tmxFile, imageResolver);
map.setOwnedResources(textures.values().toArray());
return map;
} catch (IOException e) {
throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
}
}
Aggregations