Crates.io | bevy_pancam |
lib.rs | bevy_pancam |
version | 0.15.0 |
source | src |
created_at | 2022-01-09 09:46:34.83935 |
updated_at | 2024-11-10 11:09:34.962961 |
description | A camera that allows panning by dragging with the mouse |
homepage | |
repository | https://github.com/johanhelsing/bevy_pancam |
max_upload_size | |
id | 510733 |
size | 141,933 |
A 2d-camera plugin for bevy that works with orthographic cameras.
The motivation is that this could be used for something like a map editor for a 2d game.
Behaves similarly to common online map applications:
Add the plugin to your app
App::new()
.add_plugins((DefaultPlugins, PanCamPlugin::default()))
.run();
Add the component to an orthographic camera:
commands.spawn(Camera2dBundle::default())
.insert(PanCam::default());
This is enough to get going with sensible defaults.
Alternatively, set the fields of the PanCam
component to customize behavior:
commands.spawn(Camera2dBundle::default())
.insert(PanCam {
grab_buttons: vec![MouseButton::Left, MouseButton::Middle], // which buttons should drag the camera
move_keys: DirectionKeys { // the keyboard buttons used to move the camera
up: vec![KeyCode::KeyQ], // initalize the struct like this or use the provided methods for
down: vec![KeyCode::KeyW], // common key combinations
left: vec![KeyCode::KeyE],
right: vec![KeyCode::KeyR],
},
speed: 400., // the speed for the keyboard movement
enabled: true, // when false, controls are disabled. See toggle example.
zoom_to_cursor: true, // whether to zoom towards the mouse or the center of the screen
min_scale: 1., // prevent the camera from zooming too far in
max_scale: Some(40.), // prevent the camera from zooming too far out
});
See the simple
and toggle
examples.
bevy_egui
makes pancam cameras not react when the mouse or keyboard focus is on widgets created with bevy_egui
The main
branch targets the latest bevy release.
bevy | bevy_pancam |
---|---|
0.14 | 0.12, 0.13, 0.14, 0.15, main |
0.13 | 0.11 |
0.12 | 0.10 |
0.11 | 0.9 |
0.10 | 0.8 |
0.9 | 0.7, |
0.8 | 0.5, 0.6 |
0.7 | 0.3, 0.4 |
0.6 | 0.2 |
0.5 | 0.1 |
bevy_pancam
is dual-licensed under either
at your option.
PRs welcome!