Search in sources :

Example 26 with Stage

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

the class StageTest method create.

@Override
public void create() {
    texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    stage = new Stage(new ScreenViewport());
    float loc = (NUM_SPRITES * (32 + SPACING) - SPACING) / 2;
    for (int i = 0; i < NUM_GROUPS; i++) {
        Group group = new Group();
        group.setX((float) Math.random() * (stage.getWidth() - NUM_SPRITES * (32 + SPACING)));
        group.setY((float) Math.random() * (stage.getHeight() - NUM_SPRITES * (32 + SPACING)));
        group.setOrigin(loc, loc);
        fillGroup(group, texture);
        stage.addActor(group);
    }
    uiTexture = new Texture(Gdx.files.internal("data/ui.png"));
    uiTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    ui = new Stage(new ScreenViewport());
    Image blend = new Image(new TextureRegion(uiTexture, 0, 0, 64, 32));
    blend.setAlign(Align.center);
    blend.setScaling(Scaling.none);
    blend.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            if (stage.getBatch().isBlendingEnabled())
                stage.getBatch().disableBlending();
            else
                stage.getBatch().enableBlending();
            return true;
        }
    });
    blend.setY(ui.getHeight() - 64);
    Image rotate = new Image(new TextureRegion(uiTexture, 64, 0, 64, 32));
    rotate.setAlign(Align.center);
    rotate.setScaling(Scaling.none);
    rotate.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            rotateSprites = !rotateSprites;
            return true;
        }
    });
    rotate.setPosition(64, blend.getY());
    Image scale = new Image(new TextureRegion(uiTexture, 64, 32, 64, 32));
    scale.setAlign(Align.center);
    scale.setScaling(Scaling.none);
    scale.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            scaleSprites = !scaleSprites;
            return true;
        }
    });
    scale.setPosition(128, blend.getY());
    {
        Actor shapeActor = new Actor() {

            public void drawDebug(ShapeRenderer shapes) {
                shapes.set(ShapeType.Filled);
                shapes.setColor(getColor());
                shapes.rect(getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
            }
        };
        shapeActor.setBounds(0, 0, 100, 150);
        shapeActor.setOrigin(50, 75);
        shapeActor.debug();
        sprites.add(shapeActor);
        Group shapeGroup = new Group();
        shapeGroup.setBounds(300, 300, 300, 300);
        shapeGroup.setOrigin(50, 75);
        shapeGroup.setTouchable(Touchable.childrenOnly);
        shapeGroup.addActor(shapeActor);
        stage.addActor(shapeGroup);
    }
    ui.addActor(blend);
    ui.addActor(rotate);
    ui.addActor(scale);
    fps = new Label("fps: 0", new Label.LabelStyle(font, Color.WHITE));
    fps.setPosition(10, 30);
    fps.setColor(0, 1, 0, 1);
    ui.addActor(fps);
    renderer = new ShapeRenderer();
    Gdx.input.setInputProcessor(this);
}
Also used : Group(com.badlogic.gdx.scenes.scene2d.Group) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 27 with Stage

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

the class TextAreaScrollTest method create.

@Override
public void create() {
    stage = new Stage(new ScreenViewport());
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    Gdx.input.setInputProcessor(stage);
    Table container = new Table();
    stage.addActor(container);
    container.setFillParent(true);
    container.pad(10).defaults().expandX().fillX().space(4);
    textArea = new TextArea(">>> FIRST LINE <<<\n" + "Scrolling to the bottom of the area you should see the last line.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Scrolling to the top of the area you should see the first line.\n" + ">>> LAST LINE <<<", skin) {

        public float getPrefHeight() {
            return getLines() * getStyle().font.getLineHeight();
        }
    };
    scrollPane = new ScrollPane(textArea, skin);
    scrollPane.setFadeScrollBars(false);
    scrollPane.setFlickScroll(false);
    container.row().height(350);
    container.add(scrollPane);
    container.debugAll();
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) TextArea(com.badlogic.gdx.scenes.scene2d.ui.TextArea) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport)

Example 28 with Stage

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

the class MusicTest method create.

@Override
public void create() {
    music = Gdx.audio.newMusic(Gdx.files.internal("data/8.12.mp3"));
    music.play();
    buttons = new TextureRegion(new Texture(Gdx.files.internal("data/playback.png")));
    batch = new SpriteBatch();
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    stage = new Stage();
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    slider = new Slider(0, 100, 0.1f, false, skin);
    slider.setPosition(200, 20);
    slider.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (!sliderUpdating && slider.isDragging())
                music.setPosition((slider.getValue() / 100f) * songDuration);
        }
    });
    stage.addActor(slider);
    Gdx.input.setInputProcessor(stage);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 29 with Stage

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

the class SimpleStageCullingTest method create.

@Override
public void create() {
    // create a stage and a camera controller so we can pan the view.
    stage = new Stage();
    ;
    // we know it's an ortho cam at this point!
    camController = new OrthoCamController((OrthographicCamera) stage.getCamera());
    Gdx.input.setInputProcessor(camController);
    // load a dummy texture
    texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
    // populate the stage with some actors and groups.
    for (int i = 0; i < 5000; i++) {
        Actor img = new CullableActor("img" + i, texture, (OrthographicCamera) stage.getCamera());
        img.setX((float) Math.random() * 480 * 10);
        img.setY((float) Math.random() * 320 * 10);
        stage.addActor(img);
    }
    // we also want to output the number of visible actors, so we need a SpriteBatch and a BitmapFont
    batch = new SpriteBatch();
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
}
Also used : Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 30 with Stage

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

the class SoundTest method create.

@Override
public void create() {
    sound = Gdx.audio.newSound(Gdx.files.getFileHandle("data/shotgun.ogg", FileType.Internal));
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    ui = new Stage();
    TextButton play = new TextButton("Play", skin);
    TextButton stop = new TextButton("Stop", skin);
    final Slider pitch = new Slider(0.1f, 4, 0.1f, false, skin);
    pitch.setValue(1);
    final Label pitchValue = new Label("1.0", skin);
    final Slider volume = new Slider(0.1f, 1, 0.1f, false, skin);
    volume.setValue(1);
    final Label volumeValue = new Label("1.0", skin);
    Table table = new Table();
    final Slider pan = new Slider(-1f, 1f, 0.1f, false, skin);
    pan.setValue(0);
    final Label panValue = new Label("0.0", skin);
    table.setFillParent(true);
    table.align(Align.center | Align.top);
    table.columnDefaults(0).expandX().right().uniformX();
    table.columnDefaults(2).expandX().left().uniformX();
    table.add(play);
    table.add(stop).left();
    table.row();
    table.add(new Label("Pitch", skin));
    table.add(pitch);
    table.add(pitchValue);
    table.row();
    table.add(new Label("Volume", skin));
    table.add(volume);
    table.add(volumeValue);
    table.row();
    table.add(new Label("Pan", skin));
    table.add(pan);
    table.add(panValue);
    ui.addActor(table);
    play.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            soundId = sound.play(volume.getValue());
            sound.setPitch(soundId, pitch.getValue());
            sound.setPan(soundId, pan.getValue(), volume.getValue());
        }
    });
    stop.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            sound.stop(soundId);
        }
    });
    pitch.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            sound.setPitch(soundId, pitch.getValue());
            pitchValue.setText("" + pitch.getValue());
        }
    });
    volume.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            sound.setVolume(soundId, volume.getValue());
            volumeValue.setText("" + volume.getValue());
        }
    });
    pan.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            sound.setPan(soundId, pan.getValue(), volume.getValue());
            panValue.setText("" + pan.getValue());
        }
    });
    Gdx.input.setInputProcessor(ui);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

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