LIBGDX - Xbox360 Controller joystick conversion

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

By ‘Need only recognize one direction at a time’ do you mean that it literally needs just one, so there are no diagonals? If so, then you can use the code that follows (Or something like it). Basically, you have to keep track of both axis that you’re worried about and then make decisions off of both of them. In this case, the code ensures a 0 value when it’s less than the deadzone to make computations easier. Also, when the joystick’s at a perfect 45 it’ll always favor the X axis.


public class SomethingController {
	private Vector2 lastPosition = new Vector2();
	
	// Other garbage
	
	public boolean axisMoved(Controller controllerN, int axisCode, float value) {
		if(axisCode == X_AXIS_CODE) {
			lastPosition.x = Math.abs(value) > joystickDeadZone ? value : 0;
		} else if (axisCode == Y_AXIS_CODE) {
			lastPosition.y = Math.abs(value) > joystickDeadZone ? value : 0;
		}
		if(lastPosition.x == 0 && lastPosition.y == 0) {
			// Handle the 'returned to neutral position'.
		} else if(Math.abs(lastPosition.x) > Math.abs(lastPosition.y)) {
			if(x > 0) {
				// Handle the 'direction left'.
			} else {
				// Handle the 'direction right'.
			}
		} else {
			if(y > 0) {
				// Handle the 'direction up'.
			} else {
				// Handle the 'direction up'.
			}
		}
	}
}