2014-01-09 5 views
1

내 게임 패드 (XBox)의 스틱이 풀리는 때를 확인하는 데 문제가 있습니다. 첫 번째 버튼을 누르면 버튼을 누르면 pollData = 1.0이 나오고 버튼을 놓으면 pollData = 0.0이됩니다. 아날로그 스틱으로스틱이 출시되는 방법을 찾는 방법

나는 pollData처럼 같은 이벤트가없는 = 0.0

감사를 사전에 도움을!

+0

처럼 뭔가를 할 수 있습니다. 나는 당신이'getXAxisPercentage()'메소드를 호출하여 그것을 반환 할 수 있다고 믿는다. 이 블로그에는 도움이 될만한 정보가있을 수 있습니다. http://theuzo007.wordpress.com/2012/09/02/joystick-in-java-with-jinput/ – CodeChimp

답변

1

이미 같은 축을 가지고 감안할

Component component; 

(

component.getPollData() 
를 호출하여 다음

if(component.isAnalog()) 

당신이 위치를 얻을 수를 테스트하여 축이 있는지 확인합니다

반환 값은 -1과 1 사이입니다. -1은 왼쪽/아래, 1은 오른쪽/위, component.g etIdentifier()는 Component.Identifier.Axis.X 또는 Component.Identifier.Axis.Y와 같습니다.

그래서 당신은 당신이 그들이 0 %에 있는지 확인하기 위해 조이스틱의 x 및 y 축를 얻을 수 있다고 생각

bool xReleased = false, yReleased = false; 
Component[] components = controller.getComponents(); 
for(Component component : components) { 
    if(component.isAnalog()) { //test that controller is analog 
     Identifier id = component.getIdentifier(); 
     float axisPosition = component.getPollData(); //range: -1 to 1 
     if(id == Component.Identifier.Axis.X && axisPosition == 0) 
      xReleased = true; 
     if(id == Component.Identifier.Axis.Y && axisPosition == 0) 
      yReleased = true; 
    } 
} 

if(xReleased && yReleased) { 
    //do something... 
}