Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_cursor_grab works as expected in example code but not on my own #731

Open
AntCursor opened this issue Jun 4, 2024 · 0 comments
Open

Comments

@AntCursor
Copy link

the set_cursor_grab function works totally fine in the first_person.rs example (not letting the mouse go out, and "looping" the cursor), but in my pratically equal code it doesn't:
(Ignore my bad skill)

mod camera;

use camera::FirstPerson;
use macroquad::{
    miniquad::window::{set_cursor_grab, show_mouse},
    prelude::*,
};

const MOVE_SPEED: f32 = 0.2;
const LOOK_SPEED: f32 = 10.;

#[macroquad::main("3D")]
async fn main() {
    let mut cam: FirstPerson = FirstPerson {
        ..Default::default()
    };

    let mut grabbed = true;
    set_cursor_grab(grabbed);
    show_mouse(false);

    loop {
        clear_background(LIGHTGRAY);

        let delta = get_frame_time();

        if is_key_pressed(KeyCode::Escape) {
            break;
        }
        if is_key_pressed(KeyCode::Tab) {
            grabbed = !grabbed;
            set_cursor_grab(grabbed);
            show_mouse(!grabbed);
        }
        cam.movement(MOVE_SPEED);

        let mouse_delta = -mouse_delta_position();
        cam.mouse_direction_change(mouse_delta, LOOK_SPEED, delta);

        set_camera(&cam.get_camera());

        draw_grid(100, 1., BLACK, GRAY);

        set_default_camera();
        draw_text(
            &format!("{:?}  {:?}", mouse_position_local(), mouse_delta),
            15.,
            15.,
            20.,
            RED,
        );

        next_frame().await;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant