Search in sources :

Example 6 with Batch

use of com.badlogic.gdx.graphics.g2d.Batch in project var3dframe by Var3D.

the class VStage method batchBegin.

public Batch batchBegin() {
    Batch batch = super.getBatch();
    batch.begin();
    batch.setColor(Color.WHITE);
    oldTransform.set(batch.getTransformMatrix());
    batch.setTransformMatrix(computeTransform());
    return batch;
}
Also used : Batch(com.badlogic.gdx.graphics.g2d.Batch)

Example 7 with Batch

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

the class Stage method draw.

public void draw() {
    Camera camera = viewport.getCamera();
    camera.update();
    if (!root.isVisible())
        return;
    Batch batch = this.batch;
    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    root.draw(batch, 1);
    batch.end();
    if (debug)
        drawDebug();
}
Also used : Batch(com.badlogic.gdx.graphics.g2d.Batch) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Camera(com.badlogic.gdx.graphics.Camera) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera)

Example 8 with Batch

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

the class SuperKoalio method renderKoala.

private void renderKoala(float deltaTime) {
    // based on the koala state, get the animation frame
    TextureRegion frame = null;
    switch(koala.state) {
        case Standing:
            frame = stand.getKeyFrame(koala.stateTime);
            break;
        case Walking:
            frame = walk.getKeyFrame(koala.stateTime);
            break;
        case Jumping:
            frame = jump.getKeyFrame(koala.stateTime);
            break;
    }
    // draw the koala, depending on the current velocity
    // on the x-axis, draw the koala facing either right
    // or left
    Batch batch = renderer.getBatch();
    batch.begin();
    if (koala.facesRight) {
        batch.draw(frame, koala.position.x, koala.position.y, Koala.WIDTH, Koala.HEIGHT);
    } else {
        batch.draw(frame, koala.position.x + Koala.WIDTH, koala.position.y, -Koala.WIDTH, Koala.HEIGHT);
    }
    batch.end();
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Batch(com.badlogic.gdx.graphics.g2d.Batch)

Example 9 with Batch

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

the class Scene2dTest method create.

public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    final TextureRegion region = new TextureRegion(new Texture("data/badlogic.jpg"));
    final Actor actor = new Actor() {

        public void draw(Batch batch, float parentAlpha) {
            Color color = getColor();
            batch.setColor(color.r, color.g, color.b, parentAlpha);
            batch.draw(region, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
        }
    };
    actor.setBounds(15, 15, 100, 100);
    actor.setOrigin(50, 50);
    stage.addActor(actor);
    actor.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("down");
            return true;
        }

        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("up " + event.getTarget());
        }
    });
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    VerticalGroup g = new VerticalGroup().space(5).reverse().pad(5).fill();
    for (int i = 0; i < 10; i++) g.addActor(new TextButton("button " + i, skin));
    g.addActor(new TextButton("longer button", skin));
    Table table = new Table().debug();
    table.add(g);
    table.pack();
    table.setPosition(5, 100);
    stage.addActor(table);
    HorizontalGroup h = new HorizontalGroup().space(5).reverse().pad(5).fill();
    for (int i = 0; i < 5; i++) h.addActor(new TextButton("button " + i, skin));
    h.addActor(new TextButton("some taller\nbutton", skin));
    table = new Table().debug();
    table.add(h);
    table.pack();
    table.setPosition(130, 100);
    stage.addActor(table);
    table.toFront();
    final TextButton button = new TextButton("Fancy Background", skin);
    // button.addListener(new ClickListener() {
    // public void clicked (InputEvent event, float x, float y) {
    // System.out.println("click! " + x + " " + y);
    // }
    // });
    button.addListener(new ActorGestureListener() {

        public boolean longPress(Actor actor, float x, float y) {
            System.out.println("long press " + x + ", " + y);
            return true;
        }

        public void fling(InputEvent event, float velocityX, float velocityY, int button) {
            System.out.println("fling " + velocityX + ", " + velocityY);
        }

        public void zoom(InputEvent event, float initialDistance, float distance) {
            System.out.println("zoom " + initialDistance + ", " + distance);
        }

        public void pan(InputEvent event, float x, float y, float deltaX, float deltaY) {
            event.getListenerActor().moveBy(deltaX, deltaY);
            if (deltaX < 0)
                System.out.println("panning " + deltaX + ", " + deltaY + " " + event.getTarget());
        }
    });
    // button.addListener(new ChangeListener() {
    // public void changed (ChangeEvent event, Actor actor) {
    // // event.cancel();
    // }
    // });
    button.setPosition(50, 50);
    stage.addActor(button);
    // List select = new List(skin);
    // select.setBounds(200, 200, 100, 100);
    // select.setItems(new Object[] {1, 2, 3, 4, 5});
    // stage.addActor(select);
    // stage.addListener(new ChangeListener() {
    // public void changed (ChangeEvent event, Actor actor) {
    // System.out.println(actor);
    // }
    // });
    meow.setDuration(2);
    actor.addAction(forever(sequence(moveBy(50, 0, 2), moveBy(-50, 0, 2), run(new Runnable() {

        public void run() {
            actor.setZIndex(0);
        }
    }))));
    // actor.addAction(parallel(rotateBy(90, 2), rotateBy(90, 2)));
    // actor.addAction(parallel(moveTo(250, 250, 2, elasticOut), color(RED, 6), delay(0.5f), rotateTo(180, 5, swing)));
    // actor.addAction(forever(sequence(scaleTo(2, 2, 0.5f), scaleTo(1, 1, 0.5f), delay(0.5f))));
    patch = new TiledDrawable(skin.getRegion("default-round"));
    Window window = new Window("Moo", skin);
    Label lbl = new Label("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ", skin);
    lbl.setWrap(true);
    window.row();
    window.add(lbl).width(400);
    window.pack();
    window.pack();
    stage.addActor(window);
    ImageTextButtonStyle style = new ImageTextButtonStyle(skin.get("default", TextButtonStyle.class));
    style.imageUp = skin.getDrawable("default-round");
    ImageTextButton buttonLeft = new ImageTextButton("HI IM LEFT", style);
    ImageTextButton buttonRight = new ImageTextButton("HI IM RIGHT", style) {

        {
            clearChildren();
            add(getLabel());
            add(getImage());
        }
    };
    CheckBox checkBoxLeft = new CheckBox("HI IM LEFT", skin, "default");
    CheckBox checkBoxRight = new CheckBox("HI IM RIGHT", skin, "default") {

        {
            clearChildren();
            add(getLabel());
            add(getImage());
        }
    };
    buttonLeft.setPosition(300, 400);
    buttonRight.setPosition(300, 370);
    checkBoxLeft.setPosition(150, 400);
    checkBoxRight.setPosition(150, 370);
    stage.addActor(buttonLeft);
    stage.addActor(buttonRight);
    stage.addActor(checkBoxLeft);
    stage.addActor(checkBoxRight);
    buttonLeft.debug();
    buttonRight.debug();
    checkBoxLeft.debug();
    checkBoxRight.debug();
}
Also used : ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Window(com.badlogic.gdx.scenes.scene2d.ui.Window) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) Color(com.badlogic.gdx.graphics.Color) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) VerticalGroup(com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup) Texture(com.badlogic.gdx.graphics.Texture) ActorGestureListener(com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Batch(com.badlogic.gdx.graphics.g2d.Batch) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ImageTextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton.ImageTextButtonStyle) TextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) HorizontalGroup(com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ImageTextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton.ImageTextButtonStyle)

Example 10 with Batch

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

the class TableTest method create.

@Override
public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    TextureRegion region = new TextureRegion(texture);
    NinePatch patch = skin.getPatch("default-round");
    Label label = new Label("This is some text.", skin);
    root = new Table() {

        public void draw(Batch batch, float parentAlpha) {
            super.draw(batch, parentAlpha);
        }
    };
    stage.addActor(root);
    // root.setTransform(true);
    Table table = new Table();
    table.setTransform(true);
    table.setPosition(100, 100);
    table.setOrigin(0, 0);
    table.setRotation(45);
    table.setScaleY(2);
    table.add(label);
    table.add(new TextButton("Text Button", skin));
    table.pack();
    // table.debug();
    table.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            System.out.println("click!");
        }
    });
    //		root.addActor(table);
    TextButton button = new TextButton("Text Button", skin);
    Table table2 = new Table();
    // table2.debug()
    table2.add(button);
    table2.setTransform(true);
    table2.setScaleX(1.5f);
    table2.setOrigin(table2.getPrefWidth() / 2, table2.getPrefHeight() / 2);
    // Test colspan with expandX.
    // root.setPosition(10, 10);
    root.debug();
    root.setFillParent(true);
    root.add(new Label("meow meow meow meow meow meow meow meow meow meow meow meow", skin)).colspan(3).expandX();
    root.add(new TextButton("Text Button", skin));
    root.row();
    root.add(new TextButton("Text Button", skin));
    root.add(new TextButton("Toggle Button", skin.get("toggle", TextButtonStyle.class)));
    root.add(new CheckBox("meow meow meow meow meow meow meow meow", skin));
// root.pack();
// root.add(new Button(new Image(region), skin));
// root.add(new LabelButton("Toggley", skin.getStyle("toggle", LabelButtonStyle.class)));
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) NinePatch(com.badlogic.gdx.graphics.g2d.NinePatch) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Batch(com.badlogic.gdx.graphics.g2d.Batch) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

Batch (com.badlogic.gdx.graphics.g2d.Batch)15 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)6 Camera (com.badlogic.gdx.graphics.Camera)4 Texture (com.badlogic.gdx.graphics.Texture)4 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)4 Stage (com.badlogic.gdx.scenes.scene2d.Stage)4 Group (com.badlogic.gdx.scenes.scene2d.Group)3 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)3 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)3 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)3 BaseSceneManager (com.ilargia.games.entitas.egdx.base.managers.BaseSceneManager)3 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)2 Matrix4 (com.badlogic.gdx.math.Matrix4)2 Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)2 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)2 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)2 BaseGUIManager (com.ilargia.games.entitas.egdx.base.managers.BaseGUIManager)2 Color (com.badlogic.gdx.graphics.Color)1 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1