I’m working with Libgdx’s controller library, trying to make a platformer. I want the joystick to behave like d-pad however. Specifically, I need to only recognize one direction at a time, and I need to recognize when the player lets go of the stick and it returns to the center position. Any insight to this would be much appreciated. Pardon the messy code. This is what I’ve got going so far:
public boolean axisMoved(Controller controllerN, int axisCode, float value) {
if(Math.abs(value) > joystickDeadzone){
switch(axisCode){
case 0:
if(value < 0){
controller.keyDown(ControlMapXbox.upAxis);
}
if(value > 0){
controller.keyDown(ControlMapXbox.downAxis);
}
break;
case 1:
if(value < 0){
controller.keyDown(ControlMapXbox.leftAxis);
}
if(value > 0){
controller.keyDown(ControlMapXbox.rightAxis);
}
break;
case 2:
break;
case 3:
break;
case 4:
if(value < 0){
controller.keyDown(ControlMapXbox.rightTrigger);
}
break;
}
}
return false;
}