Search in sources :

Example 1 with AtlasRegion

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

the class TextureAtlasPanel method setAtlas.

public void setAtlas(TextureAtlas atlas) {
    if (atlas == this.atlas)
        return;
    regionsPanel.removeAll();
    Array<AtlasRegion> atlasRegions = atlas.getRegions();
    CustomCardLayout layout = (CustomCardLayout) regionsPanel.getLayout();
    Array<TextureRegion> regions = new Array<TextureRegion>();
    for (Texture texture : atlas.getTextures()) {
        FileTextureData file = (FileTextureData) texture.getTextureData();
        regionsPanel.add(new TexturePanel(texture, getRegions(texture, atlasRegions, regions)));
    }
    layout.first(regionsPanel);
    this.atlas = atlas;
}
Also used : Array(com.badlogic.gdx.utils.Array) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) FileTextureData(com.badlogic.gdx.graphics.glutils.FileTextureData) Texture(com.badlogic.gdx.graphics.Texture)

Example 2 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 3 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 4 with AtlasRegion

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

the class TextureRegionDrawable method tint.

/** Creates a new drawable that renders the same as this drawable tinted the specified color. */
public Drawable tint(Color tint) {
    Sprite sprite;
    if (region instanceof AtlasRegion)
        sprite = new AtlasSprite((AtlasRegion) region);
    else
        sprite = new Sprite(region);
    sprite.setColor(tint);
    sprite.setSize(getMinWidth(), getMinHeight());
    SpriteDrawable drawable = new SpriteDrawable(sprite);
    drawable.setLeftWidth(getLeftWidth());
    drawable.setRightWidth(getRightWidth());
    drawable.setTopHeight(getTopHeight());
    drawable.setBottomHeight(getBottomHeight());
    return drawable;
}
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)

Example 5 with AtlasRegion

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

the class Skin method getDrawable.

/** Returns a registered drawable. If no drawable is found but a region, ninepatch, or sprite exists with the name, then the
	 * appropriate drawable is created and stored in the skin. */
public Drawable getDrawable(String name) {
    Drawable drawable = optional(name, Drawable.class);
    if (drawable != null)
        return drawable;
    // Use texture or texture region. If it has splits, use ninepatch. If it has rotation or whitespace stripping, use sprite.
    try {
        TextureRegion textureRegion = getRegion(name);
        if (textureRegion instanceof AtlasRegion) {
            AtlasRegion region = (AtlasRegion) textureRegion;
            if (region.splits != null)
                drawable = new NinePatchDrawable(getPatch(name));
            else if (region.rotate || region.packedWidth != region.originalWidth || region.packedHeight != region.originalHeight)
                drawable = new SpriteDrawable(getSprite(name));
        }
        if (drawable == null)
            drawable = new TextureRegionDrawable(textureRegion);
    } catch (GdxRuntimeException ignored) {
    }
    // Check for explicit registration of ninepatch, sprite, or tiled drawable.
    if (drawable == null) {
        NinePatch patch = optional(name, NinePatch.class);
        if (patch != null)
            drawable = new NinePatchDrawable(patch);
        else {
            Sprite sprite = optional(name, Sprite.class);
            if (sprite != null)
                drawable = new SpriteDrawable(sprite);
            else
                throw new GdxRuntimeException("No Drawable, NinePatch, TextureRegion, Texture, or Sprite registered with name: " + name);
        }
    }
    if (drawable instanceof BaseDrawable)
        ((BaseDrawable) drawable).setName(name);
    add(name, drawable, Drawable.class);
    return drawable;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) NinePatch(com.badlogic.gdx.graphics.g2d.NinePatch) BaseDrawable(com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) BaseDrawable(com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)

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