Search in sources :

Example 61 with GdxRuntimeException

use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.

the class BitmapFontLoader method loadSync.

@Override
public BitmapFont loadSync(AssetManager manager, String fileName, FileHandle file, BitmapFontParameter parameter) {
    if (parameter != null && parameter.atlasName != null) {
        TextureAtlas atlas = manager.get(parameter.atlasName, TextureAtlas.class);
        String name = file.sibling(data.imagePaths[0]).nameWithoutExtension().toString();
        AtlasRegion region = atlas.findRegion(name);
        if (region == null)
            throw new GdxRuntimeException("Could not find font region " + name + " in atlas " + parameter.atlasName);
        return new BitmapFont(file, region);
    } else {
        int n = data.getImagePaths().length;
        Array<TextureRegion> regs = new Array(n);
        for (int i = 0; i < n; i++) {
            regs.add(new TextureRegion(manager.get(data.getImagePath(i), Texture.class)));
        }
        return new BitmapFont(data, regs, true);
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Array(com.badlogic.gdx.utils.Array) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 62 with GdxRuntimeException

use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.

the class TextureArray method reload.

@Override
protected void reload() {
    if (!isManaged())
        throw new GdxRuntimeException("Tried to reload an unmanaged TextureArray");
    glHandle = Gdx.gl.glGenTexture();
    load(data);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Example 63 with GdxRuntimeException

use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.

the class FileHandle method moveTo.

/** Moves this file to the specified file, overwriting the file if it already exists.
	 * @throws GdxRuntimeException if the source or destination file handle is a {@link FileType#Classpath} or
	 *            {@link FileType#Internal} file. */
public void moveTo(FileHandle dest) {
    if (type == FileType.Classpath)
        throw new GdxRuntimeException("Cannot move a classpath file: " + file);
    if (type == FileType.Internal)
        throw new GdxRuntimeException("Cannot move an internal file: " + file);
    copyTo(dest);
    delete();
    if (exists() && isDirectory())
        deleteDirectory();
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Example 64 with GdxRuntimeException

use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.

the class FileHandle method write.

/** Reads the remaining bytes from the specified stream and writes them to this file. The stream is closed. Parent directories
	 * will be created if necessary.
	 * @param append If false, this file will be overwritten if it exists, otherwise it will be appended.
	 * @throws GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or
	 *            {@link FileType#Internal} file, or if it could not be written. */
public void write(InputStream input, boolean append) {
    OutputStream output = null;
    try {
        output = write(append);
        StreamUtils.copyStream(input, output);
    } catch (Exception ex) {
        throw new GdxRuntimeException("Error stream writing to file: " + file + " (" + type + ")", ex);
    } finally {
        StreamUtils.closeQuietly(input);
        StreamUtils.closeQuietly(output);
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 65 with GdxRuntimeException

use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.

the class FileHandle method readBytes.

/** Reads the entire file into the byte array. The byte array must be big enough to hold the file's data.
	 * @param bytes the array to load the file into
	 * @param offset the offset to start writing bytes
	 * @param size the number of bytes to read, see {@link #length()}
	 * @return the number of read bytes */
public int readBytes(byte[] bytes, int offset, int size) {
    InputStream input = read();
    int position = 0;
    try {
        while (true) {
            int count = input.read(bytes, offset + position, size - position);
            if (count <= 0)
                break;
            position += count;
        }
    } catch (IOException ex) {
        throw new GdxRuntimeException("Error reading file: " + this, ex);
    } finally {
        StreamUtils.closeQuietly(input);
    }
    return position - offset;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Aggregations

GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)202 IOException (java.io.IOException)40 FileHandle (com.badlogic.gdx.files.FileHandle)14 Array (com.badlogic.gdx.utils.Array)13 Texture (com.badlogic.gdx.graphics.Texture)12 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)11 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)9 InputStream (java.io.InputStream)9 Pixmap (com.badlogic.gdx.graphics.Pixmap)8 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)8 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)7 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)7 BufferedInputStream (java.io.BufferedInputStream)7 File (java.io.File)7 OutputStream (java.io.OutputStream)7 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)6 LifecycleListener (com.badlogic.gdx.LifecycleListener)5 ByteBuffer (java.nio.ByteBuffer)5 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)4 NinePatch (com.badlogic.gdx.graphics.g2d.NinePatch)4