Search in sources :

Example 6 with Stage

use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.

the class ViewportTest1 method create.

public void create() {
    stage = new Stage();
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    label = new Label("", skin);
    Table root = new Table(skin);
    root.setFillParent(true);
    root.setBackground(skin.getDrawable("default-pane"));
    root.debug().defaults().space(6);
    root.add(new TextButton("Button 1", skin));
    root.add(new TextButton("Button 2", skin)).row();
    root.add("Press spacebar to change the viewport:").colspan(2).row();
    root.add(label).colspan(2);
    stage.addActor(root);
    viewports = getViewports(stage.getCamera());
    names = getViewportNames();
    stage.setViewport(viewports.first());
    label.setText(names.first());
    Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() {

        public boolean keyDown(int keycode) {
            if (keycode == Input.Keys.SPACE) {
                int index = (viewports.indexOf(stage.getViewport(), true) + 1) % viewports.size;
                label.setText(names.get(index));
                Viewport viewport = viewports.get(index);
                stage.setViewport(viewport);
                resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
            return false;
        }
    }, stage));
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) InputAdapter(com.badlogic.gdx.InputAdapter) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) StretchViewport(com.badlogic.gdx.utils.viewport.StretchViewport) ExtendViewport(com.badlogic.gdx.utils.viewport.ExtendViewport) ScalingViewport(com.badlogic.gdx.utils.viewport.ScalingViewport) FitViewport(com.badlogic.gdx.utils.viewport.FitViewport) Viewport(com.badlogic.gdx.utils.viewport.Viewport) FillViewport(com.badlogic.gdx.utils.viewport.FillViewport) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 7 with Stage

use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.

the class TextAreaTest method create.

@Override
public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    TextArea textArea = new TextArea("Text Area\nEssentially, a text field\nwith\nmultiple\nlines.\n" + "It can even handle very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong lines.", skin);
    textArea.setX(10);
    textArea.setY(10);
    textArea.setWidth(200);
    textArea.setHeight(200);
    TextField textField = new TextField("Text field", skin);
    textField.setX(10);
    textField.setY(220);
    textField.setWidth(200);
    textField.setHeight(30);
    stage.addActor(textArea);
    stage.addActor(textField);
}
Also used : TextArea(com.badlogic.gdx.scenes.scene2d.ui.TextArea) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 8 with Stage

use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.

the class TextAreaTest2 method create.

@Override
public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    //Create a string that perfectly fills the float array used in the textarea float array
    FloatArray dummyArray = new FloatArray();
    String limit = "";
    // Minus one, because TextField adds a magic char
    for (int i = 0; i < dummyArray.items.length - 1; i++) {
        limit += "a";
    }
    TextArea textArea = new TextArea(limit, skin);
    textArea.setX(10);
    textArea.setY(10);
    textArea.setWidth(200);
    textArea.setHeight(200);
    stage.addActor(textArea);
}
Also used : FloatArray(com.badlogic.gdx.utils.FloatArray) TextArea(com.badlogic.gdx.scenes.scene2d.ui.TextArea) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 9 with Stage

use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.

the class TextButtonTest method create.

@Override
public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    for (int i = 0; i < 1; i++) {
        TextButton t = new TextButton("Button" + i, skin);
        t.setX(MathUtils.random(0, Gdx.graphics.getWidth()));
        t.setY(MathUtils.random(0, Gdx.graphics.getHeight()));
        t.setWidth(MathUtils.random(50, 200));
        t.setHeight(MathUtils.random(0, 100));
        stage.addActor(t);
    }
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 10 with Stage

use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.

the class TouchpadTest method create.

public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    touchpad = new Touchpad(20, skin);
    touchpad.setBounds(15, 15, 100, 100);
    stage.addActor(touchpad);
}
Also used : Touchpad(com.badlogic.gdx.scenes.scene2d.ui.Touchpad) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Aggregations

Stage (com.badlogic.gdx.scenes.scene2d.Stage)72 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)36 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)32 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)25 Texture (com.badlogic.gdx.graphics.Texture)24 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)20 Actor (com.badlogic.gdx.scenes.scene2d.Actor)19 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)18 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)16 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)16 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)15 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)14 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)13 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)13 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)9 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)8 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)6 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)5 Group (com.badlogic.gdx.scenes.scene2d.Group)5 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)4