Struct macroquad_virtual_joystick::Joystick[−][src]

pub struct Joystick { /* fields omitted */ }

The joystick component

Examples

use macroquad_virtual_joystick::Joystick;
let center_x = 100.0;
let center_y = 50.0;
let size = 50.0;
// create a new joystick
let mut joystick = Joystick::new(center_x, center_y, size);
// render the joystick and determine the action
let joystick_action = joystick.update();

Implementations

impl Joystick[src]

pub fn new(x: f32, y: f32, size: f32) -> Self[src]

create a new joystick

Arguments

  • x, y: center of the joystick
  • size: diameter of the joystick

Examples

use macroquad_virtual_joystick::Joystick;
let center_x = 100.0;
let center_y = 50.0;
let size = 50.0;
let joystick = Joystick::new(center_x, center_y, size);

pub fn from_custom_elements(
    x: f32,
    y: f32,
    size: f32,
    background: Option<JoystickElement>,
    knob: Option<JoystickElement>
) -> Self
[src]

create a new Joystick with custom elements for background and knob

Arguments

  • x, y: center of the joystick size: diameter of the joystick, should have the same size as the background element
  • background, knob: custom elements

Examples

use macroquad::prelude::Color;
use macroquad_virtual_joystick::{Joystick, JoystickElement};

let center_x = 100.0;
let center_y = 50.0;
let radius = 50.0;
let background_color = Color::from_rgba(255, 0, 0, 255);
let knob_color = Color::from_rgba(0, 255, 0, 255);

// create the background element
let background = JoystickElement::new(
    center_x,
    center_y,
    radius,
    background_color,
);

// create the knob element
let knob = JoystickElement::new(
    center_x,
    center_y,
    radius * 0.75,
    knob_color,
);

let joystick = Joystick::from_custom_elements(
    center_x,
    center_y,
    radius * 2.0,
    Some(background),
    Some(knob),
);

pub fn update(&mut self) -> JoystickDirectionalEvent[src]

update the joystick

this updates the joystick and renders it returns the current JoystickDirectionalEvent

Examples

see Joystick

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.