pub struct InputJump {
pub stickiness: Option<Duration>,
/* private fields */
}
Expand description
Used to handle jump input. This is to encapsulate all the nitty-picky logic about considering a button is still pressed a fraction of seconds after it has been pressed, etc. It does not actually poll and/or listens to the real hardware, it just keeps track of what’s happening with push/pop operations.
Fields§
§stickiness: Option<Duration>
How long a button should be considered pressed after it has actually been pressed. This is used to work around the fact that you might require a jump just before you actually land.
Implementations§
Source§impl InputJump
impl InputJump
Sourcepub fn set_stickiness_secs_f64(&mut self, stickiness_secs_f64: Option<f64>)
pub fn set_stickiness_secs_f64(&mut self, stickiness_secs_f64: Option<f64>)
Set the stickiness value, in seconds.
§Examples
use babalcore::*;
let mut input_jump = InputJump::new();
input_jump.set_stickiness_secs_f64(Some(0.1));
Sourcepub fn push_jump(&mut self, now: Option<Instant>)
pub fn push_jump(&mut self, now: Option<Instant>)
Push a jump request. It is possible to omit the current now timestamp, or you may provide your own. If omitted, the default is the current instant (AKA now). Pushing several jump requests will not queue them, only the last one is registered.
§Examples
use babalcore::*;
let mut input_jump = InputJump::new();
// Player pressed the jump key, clicked on mouse
input_jump.push_jump(None);
Sourcepub fn pop_jump(&mut self, now: Option<Instant>) -> bool
pub fn pop_jump(&mut self, now: Option<Instant>) -> bool
Pop a jump request. It is possible to omit the current now timestamp, or you may provide your own. If omitted, the default is the current instant (AKA now). Once a jump request is popped, it is cleared from the object. However, if stickiness is set, it will continue to return true for some time, defined by stickiness. This is to avoid the following “bug”: a player would press jump just before it can actually jump (eg: the ball did not land yet). But a fraction of a second later it would be OK to jump… You’d want it to jump now. To work around this, pop will return true for some time, typically 1/10th of a second.
§Examples
use babalcore::*;
let mut input_jump = InputJump::new();
assert!(!input_jump.pop_jump(None));
input_jump.push_jump(None);
assert!(input_jump.pop_jump(None));