12 releases (breaking)

0.11.1 Mar 21, 2024
0.10.0 Nov 6, 2023
0.9.0 Jul 13, 2023
0.8.0 Mar 9, 2023
0.2.0 Jan 9, 2022

#89 in Game dev

Download history 299/week @ 2023-12-22 180/week @ 2023-12-29 251/week @ 2024-01-05 271/week @ 2024-01-12 197/week @ 2024-01-19 183/week @ 2024-01-26 201/week @ 2024-02-02 209/week @ 2024-02-09 457/week @ 2024-02-16 526/week @ 2024-02-23 384/week @ 2024-03-01 420/week @ 2024-03-08 484/week @ 2024-03-15 342/week @ 2024-03-22 402/week @ 2024-03-29 276/week @ 2024-04-05

1,550 downloads per month
Used in 7 crates

MIT/Apache

34KB
282 lines

bevy_pancam

crates.io MIT/Apache 2.0 crates.io docs.rs

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.

Controls

Behaves similarly to common online map applications:

  • Click and drag to move the camera
  • Scroll to zoom

Usage

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
        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.

Cargo features

  • bevy_egui makes pancam cameras not react when the mouse or keyboard focus is on widgets created with bevy_egui

Bevy Version Support

The main branch targets the latest bevy release.

I intend to support the main branch of Bevy in the bevy-main branch.

bevy bevy_pancam
0.13 0.11, main
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

License

bevy_pancam is dual-licensed under either

at your option.

Contributions

PRs welcome!

Dependencies

~37–79MB
~1M SLoC