[][src]Struct babalcore::InputJump

pub struct InputJump {
    pub stickiness: Option<Duration>,
    // some fields omitted
}

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

impl InputJump[src]

pub fn new() -> InputJump[src]

Create a new input jump manager.

Examples

use babalcore::*;

let _input_jump = InputJump::new();

pub fn set_stickiness_secs_f64(&mut self, stickiness_secs_f64: Option<f64>)[src]

Set the stickiness value, in seconds.

Examples

use babalcore::*;

let mut input_jump = InputJump::new();
input_jump.set_stickiness_secs_f64(Some(0.1));

pub fn push_jump(&mut self, now: Option<Instant>)[src]

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);

pub fn pop_jump(&mut self, now: Option<Instant>) -> bool[src]

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));

Trait Implementations

impl Debug for InputJump[src]

impl Default for InputJump[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,