mirror of
https://github.com/bevyengine/bevy
synced 2024-12-01 08:59:11 +00:00
25bfa80e60
# Objective Yet another PR for migrating stuff to required components. This time, cameras! ## Solution As per the [selected proposal](https://hackmd.io/tsYID4CGRiWxzsgawzxG_g#Combined-Proposal-1-Selected), deprecate `Camera2dBundle` and `Camera3dBundle` in favor of `Camera2d` and `Camera3d`. Adding a `Camera` without `Camera2d` or `Camera3d` now logs a warning, as suggested by Cart [on Discord](https://discord.com/channels/691052431525675048/1264881140007702558/1291506402832945273). I would personally like cameras to work a bit differently and be split into a few more components, to avoid some footguns and confusing semantics, but that is more controversial, and shouldn't block this core migration. ## Testing I ran a few 2D and 3D examples, and tried cameras with and without render graphs. --- ## Migration Guide `Camera2dBundle` and `Camera3dBundle` have been deprecated in favor of `Camera2d` and `Camera3d`. Inserting them will now also insert the other components required by them automatically.
59 lines
1.7 KiB
Rust
59 lines
1.7 KiB
Rust
//! a test that confirms that 'bevy' does not panic while changing from Windowed to SizedFullscreen when viewport is set
|
|
|
|
use bevy::{prelude::*, render::camera::Viewport, window::WindowMode};
|
|
|
|
//Having a viewport set to the same size as a window used to cause panic on some occasions when switching to SizedFullscreen
|
|
const WINDOW_WIDTH: f32 = 1366.0;
|
|
const WINDOW_HEIGHT: f32 = 768.0;
|
|
|
|
fn main() {
|
|
//Specify Window Size.
|
|
let window = Window {
|
|
resolution: (WINDOW_WIDTH, WINDOW_HEIGHT).into(),
|
|
..default()
|
|
};
|
|
let primary_window = Some(window);
|
|
|
|
App::new()
|
|
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
|
primary_window,
|
|
..default()
|
|
}))
|
|
.add_systems(Startup, startup)
|
|
.add_systems(Update, toggle_window_mode)
|
|
.run();
|
|
}
|
|
|
|
fn startup(mut cmds: Commands) {
|
|
//Match viewport to Window size.
|
|
let physical_position = UVec2::new(0, 0);
|
|
let physical_size = Vec2::new(WINDOW_WIDTH, WINDOW_HEIGHT).as_uvec2();
|
|
let viewport = Some(Viewport {
|
|
physical_position,
|
|
physical_size,
|
|
..default()
|
|
});
|
|
|
|
cmds.spawn(Camera2d).insert(Camera {
|
|
viewport,
|
|
..default()
|
|
});
|
|
}
|
|
|
|
fn toggle_window_mode(mut qry_window: Query<&mut Window>) {
|
|
let Ok(mut window) = qry_window.get_single_mut() else {
|
|
return;
|
|
};
|
|
|
|
window.mode = match window.mode {
|
|
WindowMode::Windowed => {
|
|
//it takes a while for the window to change from windowed to sizedfullscreen and back
|
|
std::thread::sleep(std::time::Duration::from_secs(4));
|
|
WindowMode::SizedFullscreen
|
|
}
|
|
_ => {
|
|
std::thread::sleep(std::time::Duration::from_secs(4));
|
|
WindowMode::Windowed
|
|
}
|
|
};
|
|
}
|