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...') |
(No difference)
|
Revision as of 10:35, 24 April 2009
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 }