Search in sources :

Example 81 with TextureRegion

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

the class AnimationTest method render.

@Override
public void render() {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    for (int i = 0; i < cavemen.length; i++) {
        Caveman caveman = cavemen[i];
        TextureRegion frame = caveman.headsLeft ? leftWalk.getKeyFrame(caveman.stateTime, true) : rightWalk.getKeyFrame(caveman.stateTime, true);
        batch.draw(frame, caveman.pos.x, caveman.pos.y);
    }
    batch.end();
    for (int i = 0; i < cavemen.length; i++) {
        cavemen[i].update(Gdx.graphics.getDeltaTime());
    }
    fpsLog.log();
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion)

Example 82 with TextureRegion

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

the class NoncontinuousRenderingTest method create.

@Override
public void create() {
    batch = new SpriteBatch();
    texture = new Texture("data/badlogic.jpg");
    region = new TextureRegion(texture);
    stage = new Stage(new ScreenViewport(), batch);
    Gdx.input.setInputProcessor(stage);
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    skin.add("default", font = new BitmapFont(Gdx.files.internal("data/arial-32.fnt"), false));
    populateTable();
    Gdx.graphics.setContinuousRendering(false);
    Gdx.graphics.requestRendering();
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture)

Example 83 with TextureRegion

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

the class ParallaxTest method create.

@Override
public void create() {
    Texture texture = new Texture(Gdx.files.internal("data/layers.png"));
    layers = new TextureRegion[3];
    layers[0] = new TextureRegion(texture, 0, 0, 542, 363);
    layers[1] = new TextureRegion(texture, 0, 363, 1024, 149);
    layers[2] = new TextureRegion(texture, 547, 0, 224, 51);
    camera = new ParallaxCamera(480, 320);
    controller = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(controller);
    batch = new SpriteBatch();
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 84 with TextureRegion

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

the class GroupFadeTest method create.

@Override
public void create() {
    texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
    stage = new Stage();
    for (int i = 0; i < 100; i++) {
        Image img = new Image(new TextureRegion(texture));
        img.setX((float) Math.random() * 480);
        img.setY((float) Math.random() * 320);
        img.getColor().a = (float) Math.random() * 0.5f + 0.5f;
        stage.addActor(img);
    }
    stage.getRoot().addAction(forever(sequence(fadeOut(3), fadeIn(3))));
}
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 85 with TextureRegion

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

the class NinePatchTest method newPatchPix.

// Make a new 'pixmapSize' square texture region with 'patchSize' patches in it. Each patch is a different color.
static TextureRegion newPatchPix(int patchSize, int pixmapSize) {
    final int pixmapDim = MathUtils.nextPowerOfTwo(pixmapSize);
    Pixmap p = new Pixmap(pixmapDim, pixmapDim, Pixmap.Format.RGBA8888);
    p.setColor(1, 1, 1, 0);
    p.fill();
    for (int x = 0; x < pixmapSize; x += patchSize) {
        for (int y = 0; y < pixmapSize; y += patchSize) {
            p.setColor(x / (float) pixmapSize, y / (float) pixmapSize, 1.0f, 1.0f);
            p.fillRectangle(x, y, patchSize, patchSize);
        }
    }
    return new TextureRegion(new Texture(p), pixmapSize, pixmapSize);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap)

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