Get entire button state as bitmask

I have the throttle action of my game mapped to 3 buttons. I have to do 3 calls to know whether any of them are down. I also see these calls show up in the profiler, where the take like 2% of my frame. Which is a bit much imo.

It would be nice to get the entire button state as a 32bit number in Lua, which I can then mask further as desired. It could even include the crank position I think.

How exactly are you doing this? Iā€™d also double check the calls themselves are taking 2% of the frame and not something inside that call.

You could try to use input handlers which requires no queries: Inside Playdate

Building of the above reply, you could almost certainly use the input handlers to manage a button state bitmask if that works best for your game.

Just FYI, you can check also multiple inputs in one call:
playdate.buttonIsPressed( playdate.kButtonA | playdate.kButtonB )

It will return true if either A or B are pressed.

Also the query function are very lightweight so it shouldn't take 2% of your updates.

1 Like

Excellent!

Then I'll downplay this feature request to update the documentation with an example :slight_smile:

playdate.buttonIsPressed(button)

Returns true if button is currently being pressed.
button should be one of the constants:
[..]

Could also mention the example usage by @Nic

I've also added playdate.getButtonState() to match the C API, since it took about five minutes total, including documentation and filing the MR. :slight_smile:

3 Likes

Thanks @dave , works well in sdk 1.10.0 :slight_smile:

1 Like