Search in sources :

Example 76 with SpriteBatch

use of com.badlogic.gdx.graphics.g2d.SpriteBatch in project libgdx by libgdx.

the class PngTest method create.

public void create() {
    batch = new SpriteBatch();
    badlogic = new Texture(Gdx.files.internal("data/badlogic.jpg"));
}
Also used : SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture)

Example 77 with SpriteBatch

use of com.badlogic.gdx.graphics.g2d.SpriteBatch in project libgdx by libgdx.

the class TextButtonTest method render.

@Override
public void render() {
    Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    stage.draw();
    Gdx.app.log("X", "FPS: " + Gdx.graphics.getFramesPerSecond());
    SpriteBatch spriteBatch = (SpriteBatch) stage.getBatch();
    Gdx.app.log("X", "render calls: " + spriteBatch.totalRenderCalls);
    spriteBatch.totalRenderCalls = 0;
}
Also used : SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 78 with SpriteBatch

use of com.badlogic.gdx.graphics.g2d.SpriteBatch in project libgdx by libgdx.

the class TextInputDialogTest method create.

public void create() {
    message = "Touch screen for dialog";
    batch = new SpriteBatch();
    font = new BitmapFont();
    Gdx.input.getTextInput(new TextInputListener() {

        @Override
        public void input(String text) {
            message = "message: " + text + ", touch screen for new dialog";
        }

        @Override
        public void canceled() {
            message = "cancled by user";
        }
    }, "enter something funny", "funny", "something funny");
}
Also used : BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) TextInputListener(com.badlogic.gdx.Input.TextInputListener)

Example 79 with SpriteBatch

use of com.badlogic.gdx.graphics.g2d.SpriteBatch in project libgdx by libgdx.

the class TextureDownloadTest method create.

@Override
public void create() {
    new Thread(new Runnable() {

        /** Downloads the content of the specified url to the array. The array has to be big enough. */
        private int download(byte[] out, String url) {
            InputStream in = null;
            try {
                HttpURLConnection conn = null;
                conn = (HttpURLConnection) new URL(url).openConnection();
                conn.setDoInput(true);
                conn.setDoOutput(false);
                conn.setUseCaches(true);
                conn.connect();
                in = conn.getInputStream();
                int readBytes = 0;
                while (true) {
                    int length = in.read(out, readBytes, out.length - readBytes);
                    if (length == -1)
                        break;
                    readBytes += length;
                }
                return readBytes;
            } catch (Exception ex) {
                return 0;
            } finally {
                StreamUtils.closeQuietly(in);
            }
        }

        @Override
        public void run() {
            // assuming the content is not bigger than 200kb.
            byte[] bytes = new byte[200 * 1024];
            int numBytes = download(bytes, "http://www.badlogicgames.com/wordpress/wp-content/uploads/2012/01/badlogic-new.png");
            if (numBytes != 0) {
                // load the pixmap, make it a power of two if necessary (not needed for GL ES 2.0!)
                Pixmap pixmap = new Pixmap(bytes, 0, numBytes);
                final int originalWidth = pixmap.getWidth();
                final int originalHeight = pixmap.getHeight();
                int width = MathUtils.nextPowerOfTwo(pixmap.getWidth());
                int height = MathUtils.nextPowerOfTwo(pixmap.getHeight());
                final Pixmap potPixmap = new Pixmap(width, height, pixmap.getFormat());
                potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight());
                pixmap.dispose();
                Gdx.app.postRunnable(new Runnable() {

                    @Override
                    public void run() {
                        image = new TextureRegion(new Texture(potPixmap), 0, 0, originalWidth, originalHeight);
                    }
                });
            }
        }
    }).start();
    font = new BitmapFont();
    batch = new SpriteBatch();
}
Also used : InputStream(java.io.InputStream) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) URL(java.net.URL) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) HttpURLConnection(java.net.HttpURLConnection) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 80 with SpriteBatch

use of com.badlogic.gdx.graphics.g2d.SpriteBatch 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)

Aggregations

SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)121 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)64 Texture (com.badlogic.gdx.graphics.Texture)59 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)32 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)22 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)16 Pixmap (com.badlogic.gdx.graphics.Pixmap)15 AssetManager (com.badlogic.gdx.assets.AssetManager)13 Stage (com.badlogic.gdx.scenes.scene2d.Stage)13 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)13 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)11 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)10 InputAdapter (com.badlogic.gdx.InputAdapter)9 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)9 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)8 InternalFileHandleResolver (com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver)7 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)7 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)7 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)7 Vector2 (com.badlogic.gdx.math.Vector2)7