Search in sources :

Example 71 with ChangeListener

use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project Entitas-Java by Rubentxu.

the class GuiFactory method createTouchPad.

public Touchpad createTouchPad(float width, float height, InputEntity player) {
    Touchpad touchpad = new Touchpad(10 * ScaleUtil.getSizeRatio(), skin);
    touchpad.setPosition(25 * ScaleUtil.getSizeRatio(), 15);
    touchpad.setWidth(width);
    touchpad.setHeight(height);
    PlayerInputController stateController = player.getPlayerInputController();
    touchpad.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            System.out.println("PercentX " + ((Touchpad) actor).getKnobPercentX() + "PercentY " + ((Touchpad) actor).getKnobPercentY());
            if (((Touchpad) actor).getKnobPercentX() == 0 || ((Touchpad) actor).getKnobPercentX() < 0.5 && ((Touchpad) actor).getKnobPercentX() > -0.5) {
                // controller.rightReleased();
                // controller.leftReleased();
                player.replacePlayerInputController(false, false, stateController.jumpPressed);
            }
            if (((Touchpad) actor).getKnobPercentX() > 0.5) {
                // controller.rightPressed();
                // controller.leftReleased();
                player.replacePlayerInputController(false, true, stateController.jumpPressed);
            }
            if (((Touchpad) actor).getKnobPercentX() < -0.5) {
                // controller.leftPressed();
                // controller.rightReleased();
                player.replacePlayerInputController(true, false, stateController.jumpPressed);
            }
            if (((Touchpad) actor).getKnobPercentY() > 0.5) {
                // controller.jumpPressed();
                player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, true);
            } else {
                // controller.jumpReleased();
                player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, false);
            }
        }
    });
    return touchpad;
}
Also used : PlayerInputController(com.ilargia.games.states.game.component.input.PlayerInputController) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Aggregations

Actor (com.badlogic.gdx.scenes.scene2d.Actor)71 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)71 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)51 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)43 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)38 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)25 Stage (com.badlogic.gdx.scenes.scene2d.Stage)22 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)21 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)15 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)14 SelectBox (com.badlogic.gdx.scenes.scene2d.ui.SelectBox)12 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)12 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)11 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)11 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)11 DrawableData (com.ray3k.skincomposer.data.DrawableData)11 ColorData (com.ray3k.skincomposer.data.ColorData)10 Color (com.badlogic.gdx.graphics.Color)9 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)9 Slider (com.badlogic.gdx.scenes.scene2d.ui.Slider)9