Applet using the lwjgl joystick

From JPCT
Revision as of 09:35, 24 April 2009 by AGP (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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
}