Search in sources :

Example 1 with Sprite

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

the class FilterPerformanceTest method create.

public void create() {
    batch = new SpriteBatch();
    sceneMatrix = new Matrix4().setToOrtho2D(0, 0, 480, 320);
    textMatrix = new Matrix4().setToOrtho2D(0, 0, 480, 320);
    atlas = new TextureAtlas(Gdx.files.internal("data/issue_pack"), Gdx.files.internal("data/"));
    texture = new Texture(Gdx.files.internal("data/resource1.jpg"), true);
    texture.setFilter(TextureFilter.MipMap, TextureFilter.Nearest);
    setTextureFilter(0);
    setModeString();
    sprite = atlas.createSprite("map");
    sprite2 = new Sprite(texture, 0, 0, 855, 480);
    font = new BitmapFont(Gdx.files.internal("data/font.fnt"), Gdx.files.internal("data/font.png"), false);
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean touchDown(int x, int y, int pointer, int newParam) {
            mode++;
            if (mode == filters.length * 2)
                mode = 0;
            setTextureFilter(mode / 2);
            setModeString();
            return false;
        }
    });
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) InputAdapter(com.badlogic.gdx.InputAdapter) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 2 with Sprite

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

the class BitmapFontAlignmentTest method create.

@Override
public void create() {
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean touchDown(int x, int y, int pointer, int newParam) {
            renderMode = (renderMode + 1) % 6;
            return false;
        }
    });
    spriteBatch = new SpriteBatch();
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    logoSprite = new Sprite(texture);
    logoSprite.setColor(1, 1, 1, 0.6f);
    logoSprite.setBounds(50, 100, 400, 100);
    font = new BitmapFont(Gdx.files.getFileHandle("data/verdana39.fnt", FileType.Internal), Gdx.files.getFileHandle("data/verdana39.png", FileType.Internal), false);
    cache = font.newFontCache();
    layout = new GlyphLayout();
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) InputAdapter(com.badlogic.gdx.InputAdapter) GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture)

Example 3 with Sprite

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

the class BitmapFontFlipTest method create.

@Override
public void create() {
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean touchDown(int x, int y, int pointer, int newParam) {
            renderMode = (renderMode + 1) % 4;
            return false;
        }
    });
    spriteBatch = new SpriteBatch();
    spriteBatch.setProjectionMatrix(new Matrix4().setToOrtho(0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0, 0, 1));
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    logoSprite = new Sprite(texture);
    logoSprite.flip(false, true);
    logoSprite.setPosition(0, 320 - 256);
    logoSprite.setColor(1, 1, 1, 0.5f);
    font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), Gdx.files.internal("data/verdana39.png"), true);
    cache1 = font.newFontCache();
    cache2 = font.newFontCache();
    cache3 = font.newFontCache();
    cache4 = font.newFontCache();
    cache5 = font.newFontCache();
    createCaches("cached", cache1, cache2, cache3, cache4, cache5);
    font.getData().setScale(1.33f);
    cacheScaled1 = font.newFontCache();
    cacheScaled2 = font.newFontCache();
    cacheScaled3 = font.newFontCache();
    cacheScaled4 = font.newFontCache();
    cacheScaled5 = font.newFontCache();
    createCaches("cache scaled", cacheScaled1, cacheScaled2, cacheScaled3, cacheScaled4, cacheScaled5);
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) InputAdapter(com.badlogic.gdx.InputAdapter) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 4 with Sprite

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

the class Gdx2DTest method create.

@Override
public void create() {
    batch = new SpriteBatch();
    sprites = new ArrayList<Sprite>();
    Gdx2DPixmap[] pixmaps = testPixmaps();
    Gdx2DPixmap composite = new Gdx2DPixmap(512, 256, Gdx2DPixmap.GDX2D_FORMAT_RGBA8888);
    composite.clear(0);
    composite.setBlend(Gdx2DPixmap.GDX2D_BLEND_NONE);
    for (int i = 0; i < pixmaps.length; i++) {
        composite.setScale(Gdx2DPixmap.GDX2D_SCALE_NEAREST);
        composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 0, 64, 64);
        composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 64, 16, 16);
        composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 0, 64, 64);
        composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 64, 16, 16);
        composite.setScale(Gdx2DPixmap.GDX2D_SCALE_LINEAR);
        composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 100, 64, 64);
        composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 164, 16, 16);
        composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 100, 64, 64);
        composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 164, 16, 16);
        Sprite sprite = new Sprite(textureFromPixmap(pixmaps[i]));
        sprite.setPosition(10 + i * 32, 10);
        sprites.add(sprite);
    }
    Sprite sprite = new Sprite(textureFromPixmap(composite));
    sprite.setPosition(10, 50);
    sprites.add(sprite);
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Gdx2DPixmap(com.badlogic.gdx.graphics.g2d.Gdx2DPixmap)

Example 5 with Sprite

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

the class SpriteBatchTest method create.

@Override
public void create() {
    spriteBatch = new SpriteBatch(1000);
    Pixmap pixmap = new Pixmap(Gdx.files.internal("data/badlogicsmall.jpg"));
    texture = new Texture(32, 32, Format.RGB565);
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    texture.draw(pixmap, 0, 0);
    pixmap.dispose();
    pixmap = new Pixmap(32, 32, Format.RGBA8888);
    pixmap.setColor(1, 1, 0, 0.5f);
    pixmap.fill();
    texture2 = new Texture(pixmap);
    pixmap.dispose();
    for (int i = 0; i < sprites.length; i += 6) {
        sprites[i] = (int) (Math.random() * (Gdx.graphics.getWidth() - 32));
        sprites[i + 1] = (int) (Math.random() * (Gdx.graphics.getHeight() - 32));
        sprites[i + 2] = 0;
        sprites[i + 3] = 0;
        sprites[i + 4] = 32;
        sprites[i + 5] = 32;
        sprites2[i] = (int) (Math.random() * (Gdx.graphics.getWidth() - 32));
        sprites2[i + 1] = (int) (Math.random() * (Gdx.graphics.getHeight() - 32));
        sprites2[i + 2] = 0;
        sprites2[i + 3] = 0;
        sprites2[i + 4] = 32;
        sprites2[i + 5] = 32;
    }
    for (int i = 0; i < SPRITES * 2; i++) {
        int x = (int) (Math.random() * (Gdx.graphics.getWidth() - 32));
        int y = (int) (Math.random() * (Gdx.graphics.getHeight() - 32));
        if (i >= SPRITES)
            sprites3[i] = new Sprite(texture2, 32, 32);
        else
            sprites3[i] = new Sprite(texture, 32, 32);
        sprites3[i].setPosition(x, y);
        sprites3[i].setOrigin(16, 16);
    }
    Gdx.input.setInputProcessor(this);
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Aggregations

Sprite (com.badlogic.gdx.graphics.g2d.Sprite)40 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)19 Texture (com.badlogic.gdx.graphics.Texture)17 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)13 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)11 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)10 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)8 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)8 Test (org.junit.Test)8 SpriteDrawable (com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable)7 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)6 Pixmap (com.badlogic.gdx.graphics.Pixmap)5 NinePatch (com.badlogic.gdx.graphics.g2d.NinePatch)4 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)4 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)4 InputAdapter (com.badlogic.gdx.InputAdapter)3 Matrix4 (com.badlogic.gdx.math.Matrix4)3 Vector2 (com.badlogic.gdx.math.Vector2)3 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)3 NinePatchDrawable (com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)3