LibGDX Gamepad

I made a gamepad wrapper using JInput for a previous game. Is there any way to use gamepads with LibGDX?

Hi

As far as I know, one of its contributor talked about supporting Object Oriented Input System in the future:

Maybe I will add some support of NEWT Controller API into LibGDX in a far future.

There is already full support. http://www.badlogicgames.com/wordpress/?p=2724

@Cero do you believe it would be simple to get a Play Station 3 remote to work through that? I’m not sure if drivers would be necessary or something else…

It should work, the API is designed to support accelerometers too. I like its design, it is even more straightforward than what I have planned in my draft.

any idea where to grab a “gdx-controllers.jar”?

If you download libgdx, it is in the extensions/gdx-controller directory

Installing the gamepad is you business and could be harder than using a xbox360 pad, but I hear its easy too.
Once installed, using it with libgdx is easy as pie.
I wrote the XBox360 mappings and I plan to do one for PS3 as well if none has been posted until then.

Okay, so I got the gamepad mapping written, but now I am having the problem that when I go into fullscreen mode, the gamepad stops working.

See if you can reproduce that on another computer - I think I remember seeing something like this somewhere else where it was a driver problem

Well, haven’t had the chance to test it on another computer yet, but now when I try to start my game in fullscreen, I get this error:


terminate called after throwing an instance of 'OIS::Exception'
  what():  Win32InputManager::Win32InputManager >> The sent HWND is not valid!
AL lib: alc_cleanup: 1 device not closed

Okay, so I tested it on a 64bit Win7 Pro desktop. The same problems occurred. When I went into fullscreen, the gamepad stopped responding. It seemed to have stopped polling the hardware gamepad.

Update: I fixed it by doing two things:

First, I reloaded my gamepad each time I switched between fullscreen and not fullscreen.

Second, I changed my reload code to this:


if(Gdx.input != null) {
	Array<Controller> controllers = new DesktopControllerManager().getControllers();
	if(controllers.size > 0) gamepad = controllers.first();
}
if(gamepad != null) {
	gamepad.addListener(this);
}
hatPosition = -1;

Could you post this on the libgdx forum and/or post an issue to the libgdx issue page?
If this is a bug and not only your pc it should be known and fixed

It’s a know bug i haven’t come around to fixing yet. Your solution is interesting, i thought i needed to reinitiate the entire thing. Should be easy to fix. If someone happens to have a pull request before i get to it i won’t be mad :slight_smile: