use of com.badlogic.gdx.scenes.scene2d.InputEvent in project Entitas-Java by Rubentxu.
the class GuiFactory method createPadButtons.
public Table createPadButtons(float width, float height, InputEntity player) {
Table tableControlPad = new Table();
PlayerInputController stateController = player.getPlayerInputController();
tableControlPad.row().height(height);
ImageButton btnLeft = new ImageButton(skin, "buttonLeft");
tableControlPad.add(btnLeft).width(width).expandY().fill();
btnLeft.addListener(new ClickListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Event " + event.getType());
super.touchDown(event, x, y, pointer, button);
// controller.leftPressed();
// controller.rightReleased();
player.replacePlayerInputController(true, false, stateController.jumpPressed);
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Event " + event.getType());
super.touchUp(event, x, y, pointer, button);
// controller.leftReleased();
player.replacePlayerInputController(false, stateController.rightPressed, stateController.jumpPressed);
}
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
System.out.println("Event- " + event.getType());
super.touchDragged(event, x, y, pointer);
if (isOver(event.getListenerActor(), x, y)) {
// controller.rightReleased();
// controller.leftPressed();
player.replacePlayerInputController(true, false, stateController.jumpPressed);
} else {
// controller.leftReleased();
player.replacePlayerInputController(false, stateController.rightPressed, stateController.jumpPressed);
}
}
});
ImageButton btnRight = new ImageButton(skin, "buttonRight");
tableControlPad.add(btnRight).width(width).expandY().fill().padRight((width) * 2);
btnRight.addListener(new ClickListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Event " + event.getType());
super.touchDown(event, x, y, pointer, button);
// controller.leftReleased();
// controller.rightPressed();
player.replacePlayerInputController(false, true, stateController.jumpPressed);
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Event " + event.getType());
super.touchUp(event, x, y, pointer, button);
// controller.rightReleased();
player.replacePlayerInputController(stateController.leftPressed, false, stateController.jumpPressed);
}
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
System.out.println("Event- " + event.getType());
super.touchDragged(event, x, y, pointer);
if (isOver(event.getListenerActor(), x, y)) {
// controller.rightPressed();
// controller.leftReleased();
player.replacePlayerInputController(false, true, stateController.jumpPressed);
} else {
// controller.rightReleased();
player.replacePlayerInputController(stateController.leftPressed, false, stateController.jumpPressed);
}
}
});
ImageButton btnUP = new ImageButton(skin, "buttonUp");
tableControlPad.add(btnUP).width(width).expandY().fill();
btnUP.addListener(new ClickListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Event " + event.getType());
super.touchDown(event, x, y, pointer, button);
// controller.jumpPressed();
player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, true);
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Event " + event.getType());
super.touchUp(event, x, y, pointer, button);
// controller.jumpReleased();
player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, false);
}
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
System.out.println("Event- " + event.getType());
super.touchDragged(event, x, y, pointer);
if (isOver(event.getListenerActor(), x, y)) {
// controller.jumpPressed();
player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, true);
} else {
// controller.jumpReleased();
player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, false);
}
}
});
tableControlPad.setBounds(0, 0, Gdx.graphics.getWidth(), height + 10);
return tableControlPad;
}
Aggregations