Search in sources :

Example 1 with DirectImageResolver

use of com.badlogic.gdx.maps.ImageResolver.DirectImageResolver 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);
    }
}
Also used : DirectImageResolver(com.badlogic.gdx.maps.ImageResolver.DirectImageResolver) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ObjectMap(com.badlogic.gdx.utils.ObjectMap) FileHandle(com.badlogic.gdx.files.FileHandle) IOException(java.io.IOException) Texture(com.badlogic.gdx.graphics.Texture)

Example 2 with DirectImageResolver

use of com.badlogic.gdx.maps.ImageResolver.DirectImageResolver 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);
    }
}
Also used : DirectImageResolver(com.badlogic.gdx.maps.ImageResolver.DirectImageResolver) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ObjectMap(com.badlogic.gdx.utils.ObjectMap) FileHandle(com.badlogic.gdx.files.FileHandle) IOException(java.io.IOException) Texture(com.badlogic.gdx.graphics.Texture)

Aggregations

FileHandle (com.badlogic.gdx.files.FileHandle)2 Texture (com.badlogic.gdx.graphics.Texture)2 DirectImageResolver (com.badlogic.gdx.maps.ImageResolver.DirectImageResolver)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 ObjectMap (com.badlogic.gdx.utils.ObjectMap)2 IOException (java.io.IOException)2