Controller Input

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
drunken_munki
Party member
Posts: 134
Joined: Tue Mar 29, 2011 11:05 pm

Controller Input

Post by drunken_munki »

Hey people

I have been working on a controller input test module in the hopes that I can enable my game to use controller input at some time.

I tried several examples out there and I didn't get on with them so well because they didn't capture all the input correctly from all buttons on my test controller which is a USB XBOX 360 controller. Or at the least help me diagnose what is going on with the mappings.

Therefore I have taken some ideas and written this code that demonstrates the configuration of the mapping from love to custom button names that you create. The debug GUI will also print the love button index names of the 'last' button pressed to help you with mapping the controllers properly.

The love file attached simply runs the controller system with the optional debug mode that draws some controller information and feedback.

The controller.lua code will auto-connect a controller as it piggy backs on the love.joystickadded(joystick) and love.joystickremoved(joystick) callbacks. Be aware of this, you might want to rejig the code and cut things out as you wish. For example I just lazily mark the first controller found as the 'main' controller, i.e. index 1.

Last note: the drawControllersDebug() function will give a huge set of examples of the types of controller input checks: you can read through this to see how to use the controllerAxisVal(), controllerAxisRaw(), controllerIsDown(), controllerPressed(), and controllerReleased() functions.

TODO:
The debug function only draws the main controller, if someone wants to make the draw function draw debug info for multiple controllers that would be sweet -- I wont do this now I am too busy and only have 1 controller to test with.

Also I think this needs some sort of access function to return the list of current controllers and their indexes, which would be useful.

If someone has a controller that is not what I have, please could you tell me when running this code which buttons work or don't work? Thank you.

Final words:
This may not create an entire solution, or handle all controllers out of the box, I have only one and cant test the inputs!

Written and working with Love 0.10.2

License is granted to do as you wish.
Attachments
gamepad.love
(4.31 KiB) Downloaded 450 times
Post Reply

Who is online

Users browsing this forum: pericles and 66 guests