#cursor #bevy-plugin #bevy #camera #window #2d-3d

bevy_cursor

A bevy plugin to track information about the cursor

4 releases (2 breaking)

0.3.0 Feb 20, 2024
0.2.0 Nov 6, 2023
0.1.1 Aug 13, 2023
0.1.0 Aug 11, 2023

#570 in Game dev

Download history 117/week @ 2024-02-15 45/week @ 2024-02-22 10/week @ 2024-02-29 6/week @ 2024-03-07 14/week @ 2024-03-14 30/week @ 2024-03-21 38/week @ 2024-03-28 17/week @ 2024-04-04

90 downloads per month

MIT/Apache

31KB
120 lines

Bevy Cursor

Latest Version Bevy Tracking Doc Status Build Status

Bevy Cursor is a bevy plugin to track information about the cursor.


This plugin will track information about the position of the cursor, the window, and the camera that contains it and compute the position of the pointed point in the world position system.

Example

use bevy::prelude::*;
use bevy_cursor::prelude::*;

fn main() {
    App::new()
        .add_plugins((DefaultPlugins, TrackCursorPlugin))
        .add_systems(Startup, setup)
        .add_systems(Update, print_cursor_position)
        .run();
}

fn setup(mut commands: Commands) {
    // A camera is required to compute the world position of the cursor
    commands.spawn(Camera2dBundle::default());
}

fn print_cursor_position(cursor: Res<CursorLocation>) {
    if let Some(position) = cursor.position() {
        info!("Cursor position: {position:?}");
    } else {
        info!("The cursor is not in any window");
    }
}

Features

  • 2d opt-in the computation of the world position of the cursor.
  • 3d opt-in the computation of the ray emitted by the cursor through the camera.

Bevy compatible version

bevy bevy_cursor
0.13 0.3
0.12 0.2
0.11 0.1

Dependencies

~39–77MB
~1M SLoC