Coder Social home page Coder Social logo

bevy_cursor's Introduction

Bevy Cursor

Latest Version Bevy Tracking Doc Status Build Status

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


The following cursor informations are available via the CursorInfo resource:

  • The entity id of the window on which the cursor is currently;
  • The entity if of the camera on which the cursor is currently;
  • The position of the cursor on the window (logical position);
  • The 2D world position of the cursor (if the feature 2d is enabled);
  • The ray emitted by the cursor through the camera (if the feature 3d is enabled);

Example

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

fn main() {
    App::new()
        .add_plugins((DefaultPlugins, CursorInfoPlugin))
        .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<CursorInfo>) {
    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 (disabled by default).

Bevy compatible version

bevy bevy_cursor
0.11 0.1

bevy_cursor's People

Contributors

tguichaoua avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.