mirror of
https://github.com/bevyengine/bevy.git
synced 2026-05-06 06:06:42 -04:00
9a9817bba1
# Objective This PR fixes #21569, which proposes renaming the newly introduced camera controller modules `FreeCam` and `PanCam` to use the full term `Camera`. ## Solution * Renamed the `PanCam` controller, `PanCamPlugin`, and related methods to use the full term `Camera` instead of the abbreviation `Cam`. * Renamed the module from `pan_cam` to `pan_camera` for consistency with naming conventions. * Updated the example `pan_camera_controller` and adjusted usage of the renamed controller and plugin. * Updated documentation and release notes accordingly. ## Follow-up Work I see two options from here: 1. **Use this PR as a reference** for renaming `FreeCam`. The process is similar and could be a great first issue for someone looking to contribute to the new camera modules or Bevy in general. Most of the changes follow the same pattern, although `FreeCam` has more examples that need updating. One could find them using `grep` (e.g., `grep FreeCam`) or by reviewing the diff from the PR that introduced `FreeCam`: #20215 2. **I can continue and update this PR** to also handle the `FreeCam` renaming, if you'd prefer to resolve the entire issue in one go. --------- Co-authored-by: syszery <syszery@users.noreply.github.com>
43 lines
1.4 KiB
Rust
43 lines
1.4 KiB
Rust
//! Example for `PanCamera`, demonstrating basic camera controls such as panning and zooming.
|
|
//!
|
|
//! This example shows how to use the `PanCamera` controller on a 2D camera in Bevy. The camera
|
|
//! can be panned with keyboard inputs (arrow keys or WASD) and zoomed in/out using the mouse
|
|
//! wheel or the +/- keys. The camera starts with the default `PanCamera` settings, which can
|
|
//! be customized.
|
|
//!
|
|
//! Controls:
|
|
//! - Arrow keys (or WASD) to pan the camera.
|
|
//! - Mouse scroll wheel or +/- to zoom in/out.
|
|
|
|
use bevy::camera_controller::pan_camera::{PanCamera, PanCameraPlugin};
|
|
use bevy::prelude::*;
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins(DefaultPlugins)
|
|
.add_plugins(PanCameraPlugin) // Adds the PanCamera plugin to enable camera panning and zooming controls.
|
|
.add_systems(Startup, (setup, spawn_text).chain())
|
|
.run();
|
|
}
|
|
|
|
fn spawn_text(mut commands: Commands, camera: Query<&PanCamera>) {
|
|
commands.spawn((
|
|
Node {
|
|
position_type: PositionType::Absolute,
|
|
top: px(-16),
|
|
left: px(12),
|
|
..default()
|
|
},
|
|
children![Text::new(format!("{}", camera.single().unwrap()))],
|
|
));
|
|
}
|
|
|
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|
// Spawn a 2D Camera with default PanCamera settings
|
|
commands.spawn((Camera2d, PanCamera::default()));
|
|
|
|
commands.spawn(Sprite::from_image(
|
|
asset_server.load("branding/bevy_bird_dark.png"),
|
|
));
|
|
}
|