Search in sources :

Example 76 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.

the class PngTest method render.

public void render() {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    if (screenshot == null) {
        int width = Gdx.graphics.getWidth(), height = Gdx.graphics.getHeight();
        for (int i = 0; i < 100; i++) batch.draw(badlogic, MathUtils.random(width), MathUtils.random(height));
        batch.flush();
        FileHandle file = FileHandle.tempFile("screenshot-");
        System.out.println(file.file().getAbsolutePath());
        Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        try {
            PNG writer = new PNG((int) (pixmap.getWidth() * pixmap.getHeight() * 1.5f));
            // writer.setCompression(Deflater.NO_COMPRESSION);
            writer.write(file, pixmap);
            // Write twice to make sure the object is reusable.
            writer.write(file, pixmap);
            writer.dispose();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        screenshot = new Texture(file);
    }
    batch.draw(screenshot, 0, 0);
    batch.end();
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) PNG(com.badlogic.gdx.graphics.PixmapIO.PNG) IOException(java.io.IOException) Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 77 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.

the class TextureFormatTest method create.

@Override
public void create() {
    FileHandle file = Gdx.files.internal("data/bobargb8888-32x32.png");
    nonMipMapped[0] = new Texture(file, Format.Alpha, false);
    nonMipMapped[1] = new Texture(file, Format.LuminanceAlpha, false);
    nonMipMapped[2] = new Texture(file, Format.RGB888, false);
    nonMipMapped[3] = new Texture(file, Format.RGB565, false);
    nonMipMapped[4] = new Texture(file, Format.RGBA8888, false);
    nonMipMapped[5] = new Texture(file, Format.RGBA4444, false);
    mipMapped[0] = new Texture(file, Format.Alpha, true);
    mipMapped[1] = new Texture(file, Format.LuminanceAlpha, true);
    mipMapped[2] = new Texture(file, Format.RGB888, true);
    mipMapped[3] = new Texture(file, Format.RGB565, true);
    mipMapped[4] = new Texture(file, Format.RGBA8888, true);
    mipMapped[5] = new Texture(file, Format.RGBA4444, true);
    batch = new SpriteBatch();
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 78 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.

the class ResolutionFileResolver method resolve.

@Override
public FileHandle resolve(String fileName) {
    Resolution bestResolution = choose(descriptors);
    FileHandle originalHandle = new FileHandle(fileName);
    FileHandle handle = baseResolver.resolve(resolve(originalHandle, bestResolution.folder));
    if (!handle.exists())
        handle = baseResolver.resolve(fileName);
    return handle;
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle)

Example 79 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project Entitas-Java by Rubentxu.

the class TestFileHandleResolver method resolve.

@Override
public FileHandle resolve(String fileName) {
    URL url = Thread.currentThread().getContextClassLoader().getResource(fileName);
    File file = new File(url.getPath());
    return new FileHandle(file);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) File(java.io.File) URL(java.net.URL)

Aggregations

FileHandle (com.badlogic.gdx.files.FileHandle)79 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)23 IOException (java.io.IOException)22 Array (com.badlogic.gdx.utils.Array)18 File (java.io.File)18 Element (com.badlogic.gdx.utils.XmlReader.Element)9 Texture (com.badlogic.gdx.graphics.Texture)8 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)7 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)7 IntArray (com.badlogic.gdx.utils.IntArray)7 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)6 AssetDescriptor (com.badlogic.gdx.assets.AssetDescriptor)5 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)4 TextureAtlasData (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData)4 Json (com.badlogic.gdx.utils.Json)4 GwtFileHandle (com.badlogic.gdx.backends.gwt.GwtFileHandle)3 Color (com.badlogic.gdx.graphics.Color)3 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 Writer (java.io.Writer)3