Ever wish PICO-8 had dual analog stick support? Me too. Pinput is a Lua library that works with PICO-8's GPIO memory area and an external helper app t

VyrCossont / Pinput Public

submited by
Style Pass
2022-01-12 14:00:12

Ever wish PICO-8 had dual analog stick support? Me too. Pinput is a Lua library that works with PICO-8's GPIO memory area and an external helper app to provide XInput-like gamepad support to an unmodifed copy of PICO-8. This gets you two analog sticks, two analog triggers, up to 16 digital buttons, and even rumble support, for up to 8 gamepads. Pinput supports macOS, Windows, Linux, Chrome, Firefox, and Safari.

To add Pinput support to your own cartridge, take a look at pinput.lua. All of the functions and constants prefixed with pi_ are the Pinput client code proper, and you can copy or #include pinput.lua that code right into your cartridge to use it yourself.

Call pi_init() to put the Pinput magic bytes into GPIO so one of the helper apps can find it and start communicating, and call pi_btn(), pi_trigger(), pi_axis(), etc. to read button, trigger, and thumbstick axis values. Note that (as in XInput) trigger values are in the range [0, 255] and axes are in the range [-32768, 32767]. Also note that Y axes on thumbsticks are inverted, although I may change this in a future release.

Note that Pinput doesn't try to suppress PICO-8's own gamepad API, and whatever button PICO-8 uses to open the pause menu will still open the menu. However, you can use the undocumented poke(0x5f30, 1) trick to suppress the menu yourself.

Leave a Comment
Related Posts