Joypad

Struct Joypad 

Source
pub struct Joypad(/* private fields */);
Expand description

Joypad input struct.

Joypad (Buttons and D-Pad key) can be checked by writing and reading the JOYP register. (0xFF00) This struct makes it easy and safe.

The most recommended use is to receive key information on all keys at once using the Joypad::read() function for once in each frame, and then check the key press using a method.

§Examples

let key = Joypad::read();
if key.a() {
    println!("A pressed!");
}
if key.b() {
    println!("B pressed!");
}

Implementations§

Source§

impl Joypad

Source

pub fn read() -> Self

Get all buttons status.

Internally, write and read twice in the JOYP register, and returns Joypad tuple struct with bitwise OR of JoypadKey values.

Source

pub fn a(&self) -> bool

Check if A button is pressed.

Source

pub fn b(&self) -> bool

Check if B button is pressed.

Source

pub fn select(&self) -> bool

Check if Select button is pressed.

Source

pub fn start(&self) -> bool

Check if Start button is pressed.

Source

pub fn right(&self) -> bool

Check if Right of d-pad is pressed.

Source

pub fn left(&self) -> bool

Check if Left of d-pad is pressed.

Source

pub fn up(&self) -> bool

Check if Up of d-pad is pressed.

Source

pub fn down(&self) -> bool

Check if Down of d-pad is pressed.

Source

pub fn wait_until_press() -> Self

Waits until any key pressed.

Source

pub fn wait_until_release()

Waits until all key released.

Trait Implementations§

Source§

impl Clone for Joypad

Source§

fn clone(&self) -> Joypad

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl From<Joypad> for u8

Source§

fn from(value: Joypad) -> Self

Converts to this type from the input type.
Source§

impl Copy for Joypad

Auto Trait Implementations§

§

impl Freeze for Joypad

§

impl RefUnwindSafe for Joypad

§

impl Send for Joypad

§

impl Sync for Joypad

§

impl Unpin for Joypad

§

impl UnwindSafe for Joypad

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.