これは私が現在使っているコードです。 (自分ではない)。コントローラがプラグインされたことを検出し、関連する情報を数ビット出力します。私が理解できないことは、ボタンデータにアクセスする方法です。それは私が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個全ての値を表示するenterframeイベントループを追加しました。最初はすべての0を出力しますので、値を取得するのは良いですが、コントローラ上のどのボタンを押しても値が変化しません。私の方法はこれまでのところ間違っていたかもしれないので、私はそれを含めなかったのです。 – k13ran