Search in sources :

Example 6 with AtlasRegion

use of com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion 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 7 with AtlasRegion

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

the class TextureAtlasTest method create.

public void create() {
    batch = new SpriteBatch();
    renderer = new ShapeRenderer();
    atlas = new TextureAtlas(Gdx.files.internal("data/pack"));
    jumpAtlas = new TextureAtlas(Gdx.files.internal("data/jump.txt"));
    jumpAnimation = new Animation(0.25f, jumpAtlas.findRegions("ALIEN_JUMP_"));
    badlogic = atlas.createSprite("badlogicslice");
    badlogic.setPosition(50, 50);
    // badlogicSmall = atlas.createSprite("badlogicsmall");
    badlogicSmall = atlas.createSprite("badlogicsmall-rotated");
    badlogicSmall.setPosition(10, 10);
    AtlasRegion region = atlas.findRegion("badlogicsmall");
    System.out.println("badlogicSmall original size: " + region.originalWidth + ", " + region.originalHeight);
    System.out.println("badlogicSmall packed size: " + region.packedWidth + ", " + region.packedHeight);
    star = atlas.createSprite("particle-star");
    star.setPosition(10, 70);
    font = new BitmapFont(Gdx.files.internal("data/font.fnt"), atlas.findRegion("font"), false);
    Gdx.gl.glClearColor(0, 1, 0, 1);
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean keyUp(int keycode) {
            if (keycode == Keys.UP) {
                badlogicSmall.flip(false, true);
            } else if (keycode == Keys.RIGHT) {
                badlogicSmall.flip(true, false);
            } else if (keycode == Keys.LEFT) {
                badlogicSmall.setSize(512, 512);
            } else if (keycode == Keys.DOWN) {
                badlogicSmall.rotate90(true);
            }
            return super.keyUp(keycode);
        }
    });
}
Also used : TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) InputAdapter(com.badlogic.gdx.InputAdapter) Animation(com.badlogic.gdx.graphics.g2d.Animation) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 8 with AtlasRegion

use of com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion in project commons-gdx by gemserk.

the class SpriteUtilsTest method shouldReturnNotAliasWhenAtlasRegionsAreNotEqual.

@Test
public void shouldReturnNotAliasWhenAtlasRegionsAreNotEqual() {
    Sprite sprite1 = new AtlasSprite(new AtlasRegion(texture512x512, 50, 30, 40, 40));
    Sprite sprite2 = new AtlasSprite(new AtlasRegion(texture512x512, 50, 30, 20, 40));
    assertFalse(SpriteUtils.isAliasSprite(sprite1, sprite2));
}
Also used : AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) Test(org.junit.Test)

Example 9 with AtlasRegion

use of com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion in project commons-gdx by gemserk.

the class SpriteUtilsTest method shouldReturnAliasWhenAtlasRegionsAreEqual.

@Test
public void shouldReturnAliasWhenAtlasRegionsAreEqual() {
    AtlasRegion atlasRegion1 = new AtlasRegion(texture512x512, 50, 30, 40, 40);
    AtlasRegion atlasRegion2 = new AtlasRegion(texture512x512, 50, 30, 40, 40);
    Sprite sprite1 = new AtlasSprite(atlasRegion1);
    Sprite sprite2 = new AtlasSprite(atlasRegion2);
    assertTrue(SpriteUtils.isAliasSprite(sprite1, sprite2));
}
Also used : AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) Test(org.junit.Test)

Example 10 with AtlasRegion

use of com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion in project commons-gdx by gemserk.

the class FontResourceBuilder method build.

@Override
public BitmapFont build() {
    BitmapFont bitmapFont;
    if (imageFile != null && fontFile != null) {
        Texture texture = new Texture(imageFile);
        texture.setFilter(minFilter, magFilter);
        bitmapFont = new BitmapFont(fontFile, new Sprite(texture), false);
    } else if (textureAtlasId != null && regionId != null) {
        if (fontFile == null)
            throw new IllegalArgumentException("Can't build a font resource without specifying the fontFile.");
        TextureAtlas atlas = resourceManager.getResourceValue(textureAtlasId);
        AtlasRegion region = atlas.findRegion(regionId);
        if (region == null)
            throw new IllegalArgumentException("Can't build a font resource, region " + regionId + " not found in texture atlas");
        bitmapFont = new BitmapFont(fontFile, region, false);
    } else {
        // if image file and font file are not specified, it creates a new default bitmap font.
        bitmapFont = new BitmapFont();
        bitmapFont.getRegion().getTexture().setFilter(minFilter, magFilter);
    }
    bitmapFont.setUseIntegerPositions(useIntegerPositions);
    if (fixedWidthGlyphs != null)
        bitmapFont.setFixedWidthGlyphs(fixedWidthGlyphs);
    for (int i = 0; i < spacings.size(); i++) {
        FontSpacing fontSpacing = spacings.get(i);
        CharSequence charSequence = fontSpacing.charSequence;
        BitmapFontUtils.spacing(bitmapFont, charSequence, fontSpacing.spacing);
    }
    bitmapFont.setScale(scale);
    return bitmapFont;
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) Texture(com.badlogic.gdx.graphics.Texture)

Aggregations

AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)18 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)10 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)10 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)9 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)9 NinePatch (com.badlogic.gdx.graphics.g2d.NinePatch)5 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)4 Texture (com.badlogic.gdx.graphics.Texture)3 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)3 NinePatchDrawable (com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)3 SpriteDrawable (com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable)3 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)3 Array (com.badlogic.gdx.utils.Array)3 Test (org.junit.Test)3 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)2 TiledDrawable (com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable)2 InputAdapter (com.badlogic.gdx.InputAdapter)1 FileHandle (com.badlogic.gdx.files.FileHandle)1 Animation (com.badlogic.gdx.graphics.g2d.Animation)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1