2017-02-12 11 views
2

이것은 현재 사용중인 코드입니다. 내 자신이 아니야. 컨트롤러가 꽂혀있는 것을 감지하고 관련 정보를 몇 비트 출력합니다. 내가 알 수없는 것은 버튼 데이터에 액세스하는 방법입니다. PS3 컨트롤러를 연결했음을 성공적으로 인식했지만 버튼 값은 쿼리 할 때 변경되지 않는 것 같습니다.OpenFL의 PS3 컨트롤러에서 입력 하시겠습니까?

package; 

import openfl.display.Sprite; 
import openfl.events.GameInputEvent; 
import openfl.ui.GameInputControl; 
import openfl.ui.GameInputDevice; 
import openfl.ui.GameInput; 
import openfl.events.Event; 

class Main extends Sprite { 

    private var gameInput:GameInput; 

    public function new(){ 
     super(); 
     gameInput = new GameInput(); 
     gameInput.addEventListener(GameInputEvent.DEVICE_ADDED, controllerAdded); 
     gameInput.addEventListener(GameInputEvent.DEVICE_REMOVED, controllerRemoved); 
     gameInput.addEventListener(GameInputEvent.DEVICE_UNUSABLE, controllerProblem); 
    } 

    function controllerAdded(e:GameInputEvent){ 
     //put code here to handle when a device is added 

     trace("GameInput.numDevices: "+GameInput.numDevices);//tells you how many gamepads are plugged in 
     var myDevice = GameInput.getDeviceAt(0);//1st gamepad is "0" - more gamepads would be "1", "2", "3", etc. 
     trace("myDevice.numControls: "+myDevice.numControls); //tells you how many inputs/controls the device has 
     myDevice.enabled = true; //enables the device 

     var cont = myDevice.getControlAt(12);//input reference (AXIS STICK, BUTTON, TRIGGER, etc) "0" is the 1st input 
     trace("id: "+cont.id);//the name of this control. Ex: "AXIS_0" 
     trace("value: " + cont.value); //value of this control - Axis: -1 to 1, Button: 0 OR 1, Trigger: 0 to 1 
     trace("cont: " + cont.device.name); //the name of the device. ie: "XBOX 360 Controller" 
     trace("device: " + cont.device); 
     trace("minValue: " + cont.minValue);//the minimum possible value for the control/input 
     trace("maxValue: " + cont.maxValue);//the maximum possible value for the control/input 
    } 

    function controllerRemoved(e:GameInputEvent){ 
     trace('BLAH BLAH BLAH'); 
    } 

    function controllerProblem(e:GameInputEvent){ 
     //put code here to handle when there is a problem with the controller 
     trace("controller problem"); 
    } 

} 
+0

당신이 언급 한 "쿼리 된 부분"이 어떻게 처리되는지는 분명하지 않습니다. 게시 한 코드 스 니펫은 단지 한번만 트리거되어야하는 DEVICE_ADDED 이벤트에 대한 버튼 상태를 확인합니다. – Gama11

+0

내가 시도한 것이 작동하지 않기 때문에 단추 상태를 쿼리하는 코드를 구현할 수 없었습니다. PS3 컨트롤러의 모든 21 개 버튼의 값을 출력하는 엔터 프레임 이벤트 루프를 추가했습니다. 처음에는 0을 모두 출력하므로 값을 선택하는 것이 좋지만 컨트롤러에서 아무 버튼을 누르면 값이 변경되지 않습니다. 그래서 그 방법을 포함시키지 않았습니다. 왜냐하면 저의 방법이 그렇게 잘못되었을 수 있기 때문입니다. – k13ran

답변

2

다음은 컨트롤러 입력을 얻는 데 필요한 최소 코드입니다. 그것은 내가 가진 모든 컨트롤러와 함께 작동 가능 (X 박스 360, X 박스 하나와 로지텍 일) : 당신이 뭘하려 매우 유사 것 같다, 그래서 기회가 드라이버 문제가 아니라입니다 말하는 것

import openfl.display.Sprite; 
import openfl.ui.GameInput; 
import openfl.ui.GameInputDevice; 
import openfl.events.Event; 
import openfl.events.GameInputEvent; 

class Main extends Sprite { 
    public function new() { 
     super(); 
     var gameInput = new GameInput(); 
     var device:GameInputDevice; 
     gameInput.addEventListener(GameInputEvent.DEVICE_ADDED, function(event) { 
      device = event.device; 
      device.enabled = true; 
     }); 
     stage.addEventListener(Event.ENTER_FRAME, function(event) { 
      trace([for (i in 0...device.numControls) device.getControlAt(i).value]); 
     }); 
    } 
} 

코드에 문제가 있습니다. 참고 : 테스트를 위해 OpenFL 4.7.3 및 Lime 3.7.2를 사용했습니다.

저는 PS3 컨트롤러를 직접 소유하고 있지 않지만, PC에서는 작동하기가 까다 롭습니다. ScpToolkit이 자주 추천되며 꽤 인기가있는 것처럼 보입니다.

btw, openfl-samples에도 시도 할 수있는 GamepadInput 샘플이 있습니다.

+0

이것은 내 X 박스 한 컨트롤러에 완벽하게 작동합니다 (감사합니다!). 불행히도 그것은 PS3 컨트롤러에 대해 작동하지 않으며 나는 이유를 모른다. – k13ran

+0

내가 링크 된 드라이버를 설치해 보셨습니까? – Gama11

+1

드라이버 메뉴에서 옵션이 누락되었습니다.이 솔루션은 완벽하게 작동합니다 *. 정말 고맙습니다! – k13ran