pub enum JoystickDirection {
Up,
UpLeft,
Left,
DownLeft,
Down,
DownRight,
Right,
UpRight,
Idle,
}Expand description
different directions of the Joystick
Variants§
Implementations§
Source§impl JoystickDirection
impl JoystickDirection
Sourcepub fn from_degrees(degrees: f64) -> Self
pub fn from_degrees(degrees: f64) -> Self
calculate a JoystickDirection from degrees
0 degrees are on the positive X-Axis and then it rotates clockwise
§Examples
use macroquad_virtual_joystick::JoystickDirection;
let degrees = 153.5;
let direction = JoystickDirection::from_degrees(degrees);
assert_eq!(direction, JoystickDirection::DownLeft);Sourcepub fn to_local(&self) -> Vec2
pub fn to_local(&self) -> Vec2
convert the direction to a Vec2 with x and y
x and y are both one of these: [-1.0, 0.0, 1.0]
§Examples
use macroquad::prelude::Vec2;
use macroquad_virtual_joystick::JoystickDirection;
let direction = JoystickDirection::Up;
assert_eq!(direction.to_local(), Vec2::new(0.0, -1.0))Examples found in repository?
examples/simple.rs (line 13)
5async fn main() {
6 const SPEED: f32 = 2.5;
7 let mut position = Vec2::new(screen_width() / 2.0, screen_height() / 4.0);
8 let mut joystick = Joystick::new(100.0, 200.0, 50.0);
9 loop {
10 clear_background(WHITE);
11
12 let joystick_event = joystick.update();
13 position += joystick_event.direction.to_local() * joystick_event.intensity * SPEED;
14
15 draw_circle(position.x, position.y, 50.0, YELLOW);
16
17 // if you use a camera, reset the camera here with `set_default_camera()`
18 joystick.render();
19 next_frame().await
20 }
21}More examples
examples/custom.rs (line 32)
13async fn main() {
14 const SPEED: f32 = 2.5;
15 let mut position = Vec2::new(screen_width() / 2.0, screen_height() / 4.0);
16
17 let background_size = 50.0;
18 let knob_size = 32.0;
19
20 let mut joystick = Joystick::from_custom_elements(
21 100.0,
22 200.0,
23 background_size,
24 knob_size,
25 Box::new(render_background),
26 Box::new(render_knob),
27 );
28 loop {
29 clear_background(WHITE);
30
31 let joystick_event = joystick.update();
32 position += joystick_event.direction.to_local() * joystick_event.intensity * SPEED;
33
34 draw_circle(position.x, position.y, 50.0, YELLOW);
35
36 joystick.render();
37 next_frame().await
38 }
39}Trait Implementations§
Source§impl Clone for JoystickDirection
impl Clone for JoystickDirection
Source§fn clone(&self) -> JoystickDirection
fn clone(&self) -> JoystickDirection
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for JoystickDirection
Source§impl Debug for JoystickDirection
impl Debug for JoystickDirection
impl Eq for JoystickDirection
Source§impl PartialEq for JoystickDirection
impl PartialEq for JoystickDirection
impl StructuralPartialEq for JoystickDirection
Auto Trait Implementations§
impl Freeze for JoystickDirection
impl RefUnwindSafe for JoystickDirection
impl Send for JoystickDirection
impl Sync for JoystickDirection
impl Unpin for JoystickDirection
impl UnsafeUnpin for JoystickDirection
impl UnwindSafe for JoystickDirection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more