Search in sources :

Example 76 with TextureRegion

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

the class TexturePanel method draw.

private void draw(Graphics g, Array<TextureRegion> regions, Color color, boolean drawIndex) {
    int i = 0;
    for (TextureRegion region : regions) {
        int x = region.getRegionX(), y = region.getRegionY(), h = region.getRegionHeight();
        if (drawIndex) {
            String indexString = "" + i;
            Rectangle bounds = g.getFontMetrics().getStringBounds(indexString, g).getBounds();
            g.setColor(indexBackgroundColor);
            g.fillRect(x, y + h - bounds.height, bounds.width, bounds.height);
            g.setColor(indexColor);
            g.drawString(indexString, x, y + h);
            ++i;
        }
        g.setColor(color);
        g.drawRect(x, y, region.getRegionWidth(), h);
    }
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Rectangle(java.awt.Rectangle)

Example 77 with TextureRegion

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

the class Skin method getRegion.

/** Returns a registered texture region. If no region is found but a texture exists with the name, a region is created from the
	 * texture and stored in the skin. */
public TextureRegion getRegion(String name) {
    TextureRegion region = optional(name, TextureRegion.class);
    if (region != null)
        return region;
    Texture texture = optional(name, Texture.class);
    if (texture == null)
        throw new GdxRuntimeException("No TextureRegion or Texture registered with name: " + name);
    region = new TextureRegion(texture);
    add(name, region, TextureRegion.class);
    return region;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Texture(com.badlogic.gdx.graphics.Texture)

Example 78 with TextureRegion

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

the class ActionSequenceTest method create.

@Override
public void create() {
    stage = new Stage();
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), false);
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    img = new Image(new TextureRegion(texture));
    img.setSize(100, 100);
    img.setOrigin(50, 50);
    img.setPosition(100, 100);
    img2 = new Image(new TextureRegion(texture));
    img2.setSize(100, 100);
    img2.setOrigin(50, 50);
    img2.setPosition(100, 100);
    img3 = new Image(new TextureRegion(texture));
    img3.setSize(100, 100);
    img3.setOrigin(50, 50);
    img3.setPosition(100, 100);
    stage.addActor(img);
    stage.addActor(img2);
    stage.addActor(img3);
    img.addAction(sequence());
    img2.addAction(parallel(sequence(), moveBy(100, 0, 1)));
    img3.addAction(sequence(parallel(moveBy(100, 200, 2)), Actions.run(this)));
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture)

Example 79 with TextureRegion

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

the class BitmapFontDistanceFieldTest method create.

@Override
public void create() {
    camera = new OrthographicCamera();
    spriteBatch = new SpriteBatch();
    descriptionFont = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), true);
    descriptionFont.setColor(Color.RED);
    regularTexture = new Texture(Gdx.files.internal("data/verdana39.png"), true);
    regularFont = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), new TextureRegion(regularTexture), true);
    regularFont.setColor(COLOR);
    distanceFieldTexture = new Texture(Gdx.files.internal("data/verdana39distancefield.png"), true);
    distanceFieldFont = new BitmapFont(Gdx.files.internal("data/verdana39distancefield.fnt"), new TextureRegion(distanceFieldTexture), true);
    distanceFieldFont.setColor(COLOR);
    distanceFieldShader = new DistanceFieldShader();
    // Useful when debugging this test
    ShaderProgram.pedantic = false;
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture)

Example 80 with TextureRegion

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

the class ActionTest method create.

@Override
public void create() {
    stage = new Stage();
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), false);
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    final Image img = new Image(new TextureRegion(texture));
    img.setSize(100, 100);
    img.setOrigin(50, 50);
    img.setPosition(100, 100);
    // img.addAction(forever(sequence(delay(1.0f), new Action() {
    // public boolean act (float delta) {
    // System.out.println(1);
    // img.clearActions();
    // return true;
    // }
    // })));
    img.addAction(Actions.moveBy(100, 0, 2));
    img.addAction(Actions.after(Actions.scaleTo(2, 2, 2)));
    stage.addActor(img);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture)

Aggregations

TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)115 Texture (com.badlogic.gdx.graphics.Texture)57 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)22 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)18 Stage (com.badlogic.gdx.scenes.scene2d.Stage)18 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)13 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)13 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)11 NinePatch (com.badlogic.gdx.graphics.g2d.NinePatch)11 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)11 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)10 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)10 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)10 Pixmap (com.badlogic.gdx.graphics.Pixmap)8 Color (com.badlogic.gdx.graphics.Color)7 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)7 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)7 Test (org.junit.Test)7 FileHandle (com.badlogic.gdx.files.FileHandle)6 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)6