이것은 현재 사용중인 코드입니다. 내 자신이 아니야. 컨트롤러가 꽂혀있는 것을 감지하고 관련 정보를 몇 비트 출력합니다. 내가 알 수없는 것은 버튼 데이터에 액세스하는 방법입니다. 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");
}
}
당신이 언급 한 "쿼리 된 부분"이 어떻게 처리되는지는 분명하지 않습니다. 게시 한 코드 스 니펫은 단지 한번만 트리거되어야하는 DEVICE_ADDED 이벤트에 대한 버튼 상태를 확인합니다. – Gama11
내가 시도한 것이 작동하지 않기 때문에 단추 상태를 쿼리하는 코드를 구현할 수 없었습니다. PS3 컨트롤러의 모든 21 개 버튼의 값을 출력하는 엔터 프레임 이벤트 루프를 추가했습니다. 처음에는 0을 모두 출력하므로 값을 선택하는 것이 좋지만 컨트롤러에서 아무 버튼을 누르면 값이 변경되지 않습니다. 그래서 그 방법을 포함시키지 않았습니다. 왜냐하면 저의 방법이 그렇게 잘못되었을 수 있기 때문입니다. – k13ran