Search in sources :

Example 11 with Skin

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

the class LabelScaleTest method create.

@Override
public void create() {
    batch = new SpriteBatch();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    Table table = new Table();
    stage.addActor(table);
    table.setPosition(200, 65);
    Label label1 = new Label("This text is scaled 2x.", skin);
    label1.setFontScale(2);
    Label label2 = new Label("This text is scaled. This text is scaled. This text is scaled. This text is scaled. This text is scaled. ", skin);
    label2.setWrap(true);
    label2.setFontScale(0.75f, 0.75f);
    table.debug();
    table.add(label1);
    table.row();
    table.add(label2).fill();
    table.pack();
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 12 with Skin

use of com.badlogic.gdx.scenes.scene2d.ui.Skin 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 13 with Skin

use of com.badlogic.gdx.scenes.scene2d.ui.Skin 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 14 with Skin

use of com.badlogic.gdx.scenes.scene2d.ui.Skin 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)

Example 15 with Skin

use of com.badlogic.gdx.scenes.scene2d.ui.Skin in project Catacomb-Snatch by Catacomb-Snatch.

the class Art method loadResources.

/**
     * Loads all the artwork
     *
     * @return True on success, otherwise false
     */
public static boolean loadResources() {
    try {
        // Load interface
        skin = new Skin(Gdx.files.internal("art/interface.skin"), new TextureAtlas("art/interface.atlas"));
        // Load backgrounds
        pyramid = new TextureRegion(load("screen/pyramid.png"));
        // Load characters
        lordLard = cut("player/lord_lard.png", 32, 32);
        // Load tiles
        tiles_floor = cut("tiles/floor.png", 32, 32)[0];
        tiles_sand = cut("tiles/sand.png", 32, 32)[0];
        tiles_walls = cut("tiles/walls.png", 32, 56)[0];
        tiles_shadows = cut("tiles/shadows.png", 32, 32)[0];
        tiles_hole = cut("tiles/hole.png", 32, 32)[0];
        // Load extras
        logo = new TextureRegion(load("logo.png"));
        return true;
    } catch (Exception e) {
        Gdx.app.error(TAG, "Something went wrong while loading a resource: ", e);
    }
    return false;
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Aggregations

Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)41 Stage (com.badlogic.gdx.scenes.scene2d.Stage)36 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)27 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)20 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)17 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)13 Texture (com.badlogic.gdx.graphics.Texture)11 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)10 Actor (com.badlogic.gdx.scenes.scene2d.Actor)10 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)9 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)9 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)9 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)9 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)8 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)8 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)6 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)6 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)4 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)4 List (com.badlogic.gdx.scenes.scene2d.ui.List)4