Nino
(Gravity Express)
April 9, 2022, 12:50pm
1
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.
ericlewis
(Eric Lewis)
April 9, 2022, 1:47pm
2
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
sgeos
(sgeos)
April 9, 2022, 5:35pm
3
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.
Nic
(Nic Magnier)
April 10, 2022, 9:56am
4
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
Nino
(Gravity Express)
April 10, 2022, 11:57am
5
Excellent!
Then I'll downplay this feature request to update the documentation with an example
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
dave
(Dave Hayden)
April 10, 2022, 3:35pm
6
I've also added playdate.getButtonState() to match the C API, since it took about five minutes total, including documentation and filing the MR.
3 Likes
Nino
(Gravity Express)
April 19, 2022, 8:14pm
7
Thanks @dave , works well in sdk 1.10.0
1 Like