bevy_mouse_tracking_plugin
Tracking the mouse in bevy
is kind of annoying.
You gotta use Events
, and EventReader
s, and even then, they only
get called when the mouse actually moves.
This crate aims to make this as easy as possible, by providing a static resource that tracks the mouse position every frame. First, add the plugin to your app:
use *;
use MousePosPlugin;
Now, you can access the resource in your System
s:
use MousePos;
...and don't forget to add the system to your app:
.add_plugin
.add_system;
This will print the screen-space location of the mouse on every frame.
However, we can do better than just screen-space: we support automatic transformation to world-space coordinates. Change the plugin to this:
In a system...
use MousePosWorld;
This will print the world-space location of the mouse on every frame. Note that this is only supported for two-dimensional, orthographic camera, but pull requests for 3D support are welcome!
Additionally, we also support a resource that tracks mouse motion, via [MouseMotionPlugin
].
The motion can be accessed from any system in a [MouseMotion
] Res
.
As a final aside: the name of this crate is intentionally verbose.
This is because I don't want to steal a crate name, especially since
it is very likely that this crate will eventually be made redundant by
future updates to bevy
.
I recommend renaming the crate in your Cargo.toml
:
[dependencies]
mouse_tracking = { package = "bevy_mouse_tracking_plugin", version = "..." }