가능한 방법이 있습니다.
그 튜토리얼은 꽤 좋습니다. 게다가 zip 내부에있는 일부 코드를 복사하여 붙여 넣기하여 4 개의 컨트롤러를 만들 수 있다고 생각합니다. theuzo007은 여러분에게 더 많은 것을 제공합니다. 그건 그렇고, 당신이 좋아하는 그 페이지는 그 코드의 더 좋은 버전을 다운로드 할 수있는 튜토리얼의 더 좋은 버전이 있다고합니다 ->theuzo007's JInput tutorial V2
코드를 다운로드하면 JoystickTest.java에서 볼 수 있습니다. ControllerChecker
또는 더 시원한 이름의 클래스에 (대응하는 private ArrayList<Controller> foundControllers;
필드를 사용하여) 넣을 수있는 searchForControllers() 메소드가 있습니다. 그들 모두가 정적 확인하고이 같은 것을 얻을 것이다 : 즉, 반환 된 컨트롤러가 null의 경우, 점검,
public class ControllerChecker {
private static ArrayList<Controller> foundControllers = null;
/**
* Just used for checking all available controllers.
*/
private static void searchForControllers() {
Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
for(int i = 0; i < controllers.length; i++){
Controller controller = controllers[i];
if (
controller.getType() == Controller.Type.STICK ||
controller.getType() == Controller.Type.GAMEPAD ||
controller.getType() == Controller.Type.WHEEL ||
controller.getType() == Controller.Type.FINGERSTICK
)
{
// Add new controller to the list of all controllers.
foundControllers.add(controller);
// Add new controller to the list on the window.
window.addControllerName(controller.getName() + " - " + controller.getType().toString() + " type");
}
}
}
/**
* Returns null if there is no controller available. Otherwise, it retrieves the last controller in the list by removing it.
*/
public static Controller getController() {
if(foundControllers == null) {
foundControllers = new ArrayList<Controller>();
searchForControllers();
}
return foundControllers.size() == 0 ? null : foundControllers.remove(foundControllers.size() - 1);
}
} 당신은 선수가 다른 컨트롤러를 가지고 있는지 확인하기 위해 getController()
을 정적 방법을 사용
을 사용 가능한 컨트롤러가 없습니다. 또한 내 코드를 변경하고 컨트롤러를 요청할 때마다 컨트롤러를 확인할 수 있지만 컨트롤러가 이미 사용 중인지 확인해야합니다.
귀하의 목적에 도움이되기를 바랍니다. 이 솔루션은 사용 가능한 모든 컨트롤러를 확인한 다음 마지막 순서대로 반환합니다 (아마도 Stack을 사용하는 것이 더 효율적입니다). 그러나 아마도 "버튼을 눌러 특정 컨트롤러를 선택하도록 프로그램을 지시 할 수있는 것처럼 더 많은 기능을 원할 것입니다."제발, 컨트롤러를 연결하고 아무 키나 버튼을 누르십시오. "라는 화면에서. uzo007 코드를 이해하면 쉽게 달성 할 수 있습니다 (JoystickTest.java에는 많은 유용한 라인이 있습니다!).
또한 분리 된 컨트롤러를 감지 할 수있는 메커니즘을 만들 수 있으며 시스템이 다시 인식 할 수 있도록 연결하여 시스템을 인식 할 수 있습니다. 어쩌면 일부 컨트롤러 ID가 있습니다. 아직 찾지 못했습니다.
마지막으로 더 많은 코드 here이 있습니다.