Search in sources :

Example 1 with ClickListener

use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener in project Catacomb-Snatch by Catacomb-Snatch.

the class Scene method addTextButton.

/**
     * Adds a new text button
     *
     * @param text The text it contains
     * @param x    The x-position
     * @param y    The y-position
     * @return The created {@link TextButton}
     */
public TextButton addTextButton(String text, int x, int y) {
    final TextButton button = new TextButton(text, Art.skin);
    button.setPosition(x, y);
    button.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            button.act(Gdx.graphics.getDeltaTime());
        }
    });
    addActor(button);
    return button;
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 2 with ClickListener

use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener 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 3 with ClickListener

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

the class ShaderCollectionTest method createHUD.

@Override
protected void createHUD() {
    super.createHUD();
    final List<String> shadersList = new List(skin);
    shadersList.setItems(shaders);
    shadersList.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (!shadersWindow.isCollapsed() && getTapCount() == 2) {
                setShader(shadersList.getSelected());
                shadersWindow.collapse();
            }
        }
    });
    shadersWindow = addListWindow("Shaders", shadersList, -1, -1);
    final List<String> materialsList = new List(skin);
    materialsList.setItems(materials);
    materialsList.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (!materialsWindow.isCollapsed() && getTapCount() == 2) {
                setMaterial(materialsList.getSelected());
                materialsWindow.collapse();
            }
        }
    });
    materialsWindow = addListWindow("Materials", materialsList, modelsWindow.getWidth(), -1);
    final List<String> environmentsList = new List(skin);
    environmentsList.setItems(environments);
    environmentsList.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (!environmentsWindow.isCollapsed() && getTapCount() == 2) {
                setEnvironment(environmentsList.getSelected());
                environmentsWindow.collapse();
            }
        }
    });
    environmentsWindow = addListWindow("Environments", environmentsList, materialsWindow.getRight(), -1);
}
Also used : List(com.badlogic.gdx.scenes.scene2d.ui.List) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 4 with ClickListener

use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener in project AnotherMonekyParadox by SantiagoMille.

the class PantallaJuego method crearMapa.

private void crearMapa() {
    cargarTexturas();
    stageNivel = new Stage(vista);
    // Objeto que dibuja texto
    texto = new Texto(1, 1, 1);
    for (int i = 0; i < 3; i++) {
        if (i < 3) {
            vidas.add(new PowerUp(new Texture("vida.png"), camara.position.x + 10 - ANCHO / 2 + (75 * i), ALTO - 70, true));
        } else {
            vidas.add(new PowerUp(new Texture("vida.png"), camara.position.x + 10 - ANCHO / 2 + (75 * i), ALTO - 70, false));
        }
    }
    // Boton granadas
    TextureRegionDrawable btnGranada = new TextureRegionDrawable(new TextureRegion(botonGranada));
    granada = new ImageButton(btnGranada);
    granada.setSize(135, 135);
    granada.setPosition(ANCHO * 3 / 4 - granada.getWidth() / 2 + 25, ALTO / 4 - granada.getHeight() / 2 - 80);
    // boton disparo
    TextureRegionDrawable btnArma = new TextureRegionDrawable(new TextureRegion(botonDisparo));
    arma = new ImageButton(btnArma);
    arma.setSize(135, 135);
    arma.setPosition(ANCHO * 3 / 4 - arma.getWidth() / 2 + arma.getWidth() + 55, ALTO / 4 - arma.getHeight() / 2 - 80);
    // boton pausa
    TextureRegionDrawable btnPausa = new TextureRegionDrawable(new TextureRegion(botonPausa));
    pausa = new ImageButton(btnPausa);
    pausa.setSize(55, 55);
    pausa.setPosition(ANCHO / 2 - pausa.getWidth() / 2, 680 - pausa.getHeight() / 2);
    // boton continua
    TextureRegionDrawable btnContinua = new TextureRegionDrawable(new TextureRegion(botonContinua));
    continua = new ImageButton(btnContinua);
    continua.setSize(55, 55);
    continua.setPosition(ANCHO / 2 - continua.getWidth() / 2, 680 - continua.getHeight() / 2);
    // boton Home
    TextureRegionDrawable btnHome = new TextureRegionDrawable(new TextureRegion(botonHome));
    home = new ImageButton(btnContinua);
    home.setSize(55, 55);
    home.setPosition(ANCHO / 2 - continua.getWidth() / 2, 680 - continua.getHeight() / 2);
    // Texturas para el pad
    Skin skin = new Skin();
    skin.add("fondo", padBack);
    skin.add("boton", padKnob);
    Touchpad.TouchpadStyle estilo = new Touchpad.TouchpadStyle();
    estilo.background = skin.getDrawable("fondo");
    estilo.knob = skin.getDrawable("boton");
    // Crea el pad
    // Radio, estilo
    Touchpad pad = new Touchpad(64, estilo);
    // x,y - ancho,alto
    pad.setBounds(20, 20, 160, 160);
    // Comportamiento del pad
    pad.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            Touchpad pad = (Touchpad) actor;
            if (pad.getKnobPercentX() > 0.10) {
                // Más de 20% de desplazamiento DERECHA
                // personaje.setX(personaje.getX()+3);
                personaje.setRight(true);
                isMovingRight = true;
                isMovingLeft = false;
            } else if (pad.getKnobPercentX() < -0.10) {
                // Más de 20% IZQUIERDA
                // personaje.setX(personaje.getX()-3);
                personaje.setRight(false);
                isMovingLeft = true;
                isMovingRight = false;
            } else {
                isMovingLeft = false;
                isMovingRight = false;
            }
        }
    });
    // Transparente
    pad.setColor(1, 1, 1, 0.7f);
    // Comportamiento de Boton Granada
    granada.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            // Gdx.app.log("ClickListener","Si se clickeoooo");
            if (!isFliped) {
                Granada grana = new Granada(bananaGranada, false);
                grana.set(personaje.getX() + 105, personaje.getY() + 68);
                listaGranadas.add(grana);
            } else {
                Granada grana = new Granada(bananaGranada, true);
                grana.set(personaje.getX(), personaje.getY() + 68);
                listaGranadas.add(grana);
            }
        }
    });
    // Comportamiento de Boton Disparo
    arma.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            // Gdx.app.log("ClickListener","Si se clickeoooo");
            gunSound.play();
            if (!isFliped) {
                Bala nueva = new Bala(bananaDisparo, false);
                nueva.set(personaje.getX() + 105, personaje.getY() + 68);
                listaBalas.add(nueva);
            } else {
                Bala nueva = new Bala(bananaDisparo, true);
                nueva.set(personaje.getX(), personaje.getY() + 68);
                listaBalas.add(nueva);
            }
        }
    });
    // Comportamiento de Boton Pausa
    pausa.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            // Gdx.app.log("ClickListener","Si se clickeoooo");
            estado = EstadoJuego.PAUSADO;
            // main.setScreen((Screen) new EscenaPausa(vista,batch));
            if (escenaPausa == null) {
                escenaPausa = new EscenaPausa(vista, batch);
            }
            Gdx.input.setInputProcessor(escenaPausa);
            dispose();
        }
    });
    stageNivel.addActor(granada);
    stageNivel.addActor(arma);
    stageNivel.addActor(pausa);
    stageNivel.addActor(pad);
    Gdx.input.setInputProcessor(stageNivel);
}
Also used : TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Touchpad(com.badlogic.gdx.scenes.scene2d.ui.Touchpad) 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) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 5 with ClickListener

use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener in project AnotherMonekyParadox by SantiagoMille.

the class PantallaMenu method crearMenu.

private void crearMenu() {
    cargarTexturas();
    stageMenu = new Stage(vista);
    spriteBackground = new Sprite(backgroundStory);
    spriteBackground.setPosition(0, 0);
    spriteLogo = new Sprite(imgLogo);
    spriteLogo.setPosition(ANCHO / 2 - spriteLogo.getWidth() / 2, ALTO - spriteLogo.getHeight() - 40);
    // Boton Play
    TextureRegionDrawable trdPlay = new TextureRegionDrawable(new TextureRegion(botonPlay));
    TextureRegionDrawable trdPlayPressed = new TextureRegionDrawable(new TextureRegion(botonPlayPressed));
    ImageButton btnPlay = new ImageButton(trdPlay, trdPlayPressed);
    btnPlay.setPosition(ANCHO / 2 - btnPlay.getWidth() / 2, ALTO / 4 - btnPlay.getHeight() / 2);
    // Boton Leaderboard
    TextureRegionDrawable trdLead = new TextureRegionDrawable(new TextureRegion(botonLeaderboard));
    TextureRegionDrawable trdLeadPush = new TextureRegionDrawable(new TextureRegion(botonLeaderboardPressed));
    ImageButton btnLead = new ImageButton(trdLead, trdLeadPush);
    btnLead.setPosition(ANCHO / 4 - btnLead.getWidth() / 2, ALTO / 4 - btnLead.getHeight() / 2);
    // Boton about
    TextureRegionDrawable trdConfig = new TextureRegionDrawable(new TextureRegion(botonAbout));
    TextureRegionDrawable trdConfigPush = new TextureRegionDrawable(new TextureRegion(botonAboutPressed));
    ImageButton btnConfig = new ImageButton(trdConfig, trdConfigPush);
    btnConfig.setPosition(ANCHO * 3 / 4 - btnConfig.getWidth() / 2, ALTO / 4 - btnConfig.getHeight() / 2);
    // Boton Tutorial
    TextureRegionDrawable trdTut = new TextureRegionDrawable(new TextureRegion(botonTutorial));
    TextureRegionDrawable trdTutPush = new TextureRegionDrawable(new TextureRegion(botonTutorialPressed));
    ImageButton btnTut = new ImageButton(trdTut, trdTutPush);
    btnTut.setPosition(ANCHO * 13 / 14, ALTO * 13 / 14 - btnTut.getHeight() / 2);
    // Boton modo horda
    TextureRegionDrawable trdHorda = new TextureRegionDrawable(new TextureRegion(new Texture("arrow-point-to-right.png")));
    btnHorda = new ImageButton(trdHorda);
    btnHorda.setSize(60, 60);
    btnHorda.setPosition(ANCHO - btnHorda.getWidth() - 50, ALTO / 2 - btnHorda.getHeight() / 2 - 10);
    // Boton regresar de modo horda
    TextureRegionDrawable trdRegresarHorda = new TextureRegionDrawable(new TextureRegion(new Texture("arrow-point-to-left.png")));
    btnRegresarHorda = new ImageButton(trdRegresarHorda);
    btnRegresarHorda.setSize(60, 60);
    btnRegresarHorda.setVisible(false);
    btnRegresarHorda.setPosition(50, ALTO / 2 - btnRegresarHorda.getHeight() / 2 - 10);
    // Click en boton Play
    btnPlay.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            // Gdx.app.log("ClickListener","Si se clickeoooo");
            dispose();
            main.setScreen(new PantallaCargandoStoryMode(main));
        }
    });
    // Click en boton Lead
    btnLead.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            // Gdx.app.log("ClickListener","Si se clickeoooo");
            dispose();
            if (isSurvivalMode) {
                main.setScreen(new PantallaScoresSurvival(main));
            } else {
                main.setScreen(new PantallaScoresStory(main));
            }
        }
    });
    // Click en boton Developer
    btnTut.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            // Gdx.app.log("ClickListener","Si se clickeoooo");
            dispose();
            main.setScreen(new PantallaDeveloper(main));
        }
    });
    // Click en boton Horda
    btnHorda.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            isSurvivalMode = true;
            spriteBackground = new Sprite(backgroundSurvival);
            spriteBackground.setPosition(0, 0);
            btnHorda.setVisible(false);
            btnRegresarHorda.setVisible(true);
        }
    });
    // Click para regresar al modo historia
    btnRegresarHorda.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            isSurvivalMode = false;
            spriteBackground = new Sprite(backgroundStory);
            spriteBackground.setPosition(0, 0);
            btnRegresarHorda.setVisible(false);
            btnHorda.setVisible(true);
        }
    });
    // Click en boton Tutorial
    btnConfig.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            // Gdx.app.log("ClickListener","Si se clickeoooo");
            dispose();
            if (isSurvivalMode) {
                main.setScreen(new PantallaTutorialSurvivalMode(main));
            } else {
                main.setScreen(new PantallaTutorialStoryMode(main));
            }
        }
    });
    stageMenu.addActor(btnPlay);
    stageMenu.addActor(btnLead);
    stageMenu.addActor(btnConfig);
    stageMenu.addActor(btnTut);
    stageMenu.addActor(btnHorda);
    stageMenu.addActor(btnRegresarHorda);
    inputMultiplexer.addProcessor(stageMenu);
// Gdx.input.setInputProcessor(stageMenu);
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Stage(com.badlogic.gdx.scenes.scene2d.Stage) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)74 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)72 Stage (com.badlogic.gdx.scenes.scene2d.Stage)39 Texture (com.badlogic.gdx.graphics.Texture)26 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)26 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)24 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)23 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)23 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)23 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)22 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)21 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)18 Actor (com.badlogic.gdx.scenes.scene2d.Actor)17 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)12 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)7 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)7 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)6 Touchpad (com.badlogic.gdx.scenes.scene2d.ui.Touchpad)6 Texto (mx.itesm.another_monkey_paradox.Utils.Texto)6 Random (java.util.Random)5