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;
}
Aggregations