love-joycon - Switch controller support for LÖVE
Posted: Tue Mar 06, 2018 4:59 am
love-joycon
love-joycon is a smallish library that adds Joy-Con and Pro Controller support.
The library is fairly simple to use (unless you're supporting Windows, which you probably should be). Just and call the joycon.joystick* functions. If you support Windows, you'll have to register Switch controllers manually. The demo includes a simple example of how to do this.
API Reference
This is one of the required functions. Call this from love.joystickpressed and you should be good to go. The function returns true if it did anything.
This is the second required function. Call this from love.joystickreleased and you're done. The function returns true if it did anything.
The third required function that should be called from love.joystickhat. The function returns true if it did anything. This function is currently used to update the Joy-Con joystick axes, since their set up as hats in LÖVE.
The fourth required function isn't technically required. It's really just there in case the Joy-Cons' joystick axes are fixed in the future.
This function registers a joystick as a Switch controller. The type of controller is determined using the name. If the name is Pro Controller, then the joystick is registered as a Pro Controller. If the name is Joy-Con (R) or Joy-Con (L) the Joy-Con is registered according to which Joy-Con it is. If the name doesn't match any of these, it's ignored.
This function should only be required for Windows.
This is just a helper function that attempts to register the joystick automatically. On Windows, it doesn't do anything since automatic registration is broken on Windows.
Merges two Joy-Cons into one. The two joysticks should be the left and right Joy-Cons. The order they're put in doesn't matter.
It is probably possible to merge two Joy-Cons of the same type, but it would almost certainly break a lot of the code.
Separates merged Joy-Cons. Only one of the two merged joysticks needs to be passed to this function.
Returns true if the given joystick is registered as a Joy-Con.
Returns true if the given joystick is registered as any type of Switch controller.
Returns true if the given joystick is registered as a Pro Controller.
Returns true if the given joystick is a left Joy-Con.
Bugs
love-joycon is a smallish library that adds Joy-Con and Pro Controller support.
The library is fairly simple to use (unless you're supporting Windows, which you probably should be). Just
Code: Select all
joycon = require("joycon")
API Reference
Code: Select all
joycon.joystickpressed(joystick, button)
Code: Select all
joycon.joystickreleased(joystick, button)
Code: Select all
joycon.joystickhat(joystick, hat, direction)
Code: Select all
joycon.joystickaxis(joystick, axis, value)
Code: Select all
joycon.registerController(joystick, name)
This function should only be required for Windows.
Code: Select all
joycon.joystickadded(joystick)
Code: Select all
joycon.merge(joystick1, joystick2)
It is probably possible to merge two Joy-Cons of the same type, but it would almost certainly break a lot of the code.
Code: Select all
joycon.separate(joystick)
Code: Select all
joycon.isJoyCon(joystick)
Code: Select all
joycon.isSwitchController(joystick)
Code: Select all
joycon.isProController(joystick)
Code: Select all
joycon.isLeftJoyCon(joystick)
Bugs
- Can't detect Switch controllers automatically on Windows. This appears to be a problem with SDL(?). The library still works if you manually register the controllers. The demo has an example of how you could do that.
- The Joy-Cons' joysticks only have eight degrees of motion. It seems SDL thinks their joysticks are d-pads and so they're only available as hats in LÖVE.