別のプロジェクトの JInput ライブラリに慣れるために、簡単なテスト プログラムを作成しようとしています。提供されたすべてのテストクラスでコントローラーをテストしましたが、期待どおりに動作します。ただし、コントローラーをポーリングしようとすると、入力に関係なくすべての値が変更されません。ここに私が取り組んでいるコードがあります:
public class ControllerTest {
public static void main(String[] args){
//System.out.println("Hello World");
Controller[] ca = ControllerEnvironment.getDefaultEnvironment().getControllers();
Controller gamepad = null;
Component[] components = null;
EventQueue eventQueue;
// Run through the list of available input devices and get the gamepad
for(int i = 0; i < ca.length; i ++){
if(ca[i].getType().equals(Controller.Type.GAMEPAD)){
gamepad = ca[i];
}
}
// Print the name of the controller and its type
if(gamepad != null){
System.out.println(gamepad.getName() + ": " + gamepad.getType());
components = gamepad.getComponents();
System.out.println("\tComponents:");
for(int i = 0; i < components.length; i ++){
System.out.println("\t\tComponent #" + i + ": " + components[i].getName() + "\n\t\t\tIs Relative: "
+ components[i].isRelative());
}
}
else{
System.out.println("No gamepad connected");
}
while (true){
// If we have no gamepad connected, exit
if(gamepad == null){
System.out.println("No Gamepad detected, exiting...");
System.exit(0);
}
// Poll controller
gamepad.poll();
Component[] comp = gamepad.getComponents();
for(int i = 0; i < comp.length; i ++){
StringBuffer buffer = new StringBuffer();
buffer.append(comp[i].getName());
buffer.append(", Value: " + comp[i].getPollData());
System.out.println(buffer.toString());
}
try{
Thread.sleep(20); // Sleep before polling again
}
catch(InterruptedException e){
e.printStackTrace();
}
}
}
}
私はオンラインで答えを見つけようとしていますが、このライブラリは十分に文書化されておらず、通常、ゲームを作成するための他のライブラリにラップされているようです. (前述のプロジェクトは本質的にロボットです)