How, (If possible) do you tell if a button is being held? Specifically the left and right buttons. Thanks!
Might depend on the context and what you need to check in this case. Technically, Pulp isn't directly designed to track whether buttons are held and when they're released, but I suspect you could fake it a bit by checking if the player is repeatedly updating or bumping things.
You'd probably need to play with the input repeat config to try to get it to fire every frame, eg:
config.inputRepeat = 1
config.inputRepeatDelay = 0.05
config.inputRepeatBetween = 0.05
Then if you could "trap" the player using solid tiles and use "on bump", and/or use "on update", you could maintain a variable to indicate a direction hasn't changed since the previous frame. eg.
on bump do
if event.dx < 0 then
if current_direction == -1 then
// No change in direction
else
call "leftPressed" // fire initial left move event
current_direction = 1
end
else
if current_direction == -1 then
call "leftReleased" // fire event to say left has stopped being pressed
end
end
... repeat for right.
No idea if this works, but it would be how I'd start experimenting with it! If you need to actually move the player tile as well though, things would get trickier (as you probably don't want to mess with the auto repeat config).
I'm not sure if A and B buttons auto-repeat in the same way as directions.
Thanks! This is really helpful! Sorry, one more question, is there a way to check if no buttons are being pressed?
Don't think so! Using the (untested ) approach above, you'd know if anything was bumped into recently and could infer no left/right button was being held if nothing had been bumped into.
Might have a play with this later, seems like an interesting experiment to code up...
They don't unfortunately - there's no way of detecting held A and B buttons in Pulp.