Difference between revisions of "Applet using the lwjgl joystick"
From JPCT
(Created page with 'In init(): <pre> Controllers controllers = new Controllers(); try { controllers.create(); if (controllers.getControllerCount() > 0) { joystick = controllers.getContr...') |
|||
Line 23: | Line 23: | ||
} | } | ||
</pre> | </pre> | ||
+ | |||
+ | [[Category:jPCT]] | ||
+ | [[Category:LWJGL]] |
Latest revision as of 00:35, 2 February 2013
In init():
Controllers controllers = new Controllers(); try { controllers.create(); if (controllers.getControllerCount() > 0) { joystick = controllers.getController(0); System.out.println("Joystick has "+joystick.getButtonCount() +" buttons. Its name is "+joystick.getName()); } else joystick = null; } catch (org.lwjgl.LWJGLException e) {System.err.println("Couldn't initialize Controllers: "+e.getMessage());}
In the main applet loop:
if (joystick != null) { joystick.poll(); rotateZ += joystick.getXAxisValue()/2f; if (joystick.isButtonPressed(0)) ;//DO SOMETHING if (joystick.isButtonPressed(1)) ;//DO SOMETHING ELSE }