Skip to content

Commit

Permalink
Use updated window size in bevymark example (#3335)
Browse files Browse the repository at this point in the history
# Objective

Have the bird spawning/collision systems in bevymark use the proper window size, instead of the size set in WindowDescriptor which isn't updated when the window is resized.

## Solution

Use the Windows resource to grab the width/height from the primary window. This is consistent with the other examples.
  • Loading branch information
tobenaii committed Dec 18, 2021
1 parent f30f833 commit d3749a9
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions examples/tools/bevymark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct BirdTexture(Handle<Image>);

fn setup(
mut commands: Commands,
window: Res<WindowDescriptor>,
windows: Res<Windows>,
mut counter: ResMut<BevyCounter>,
asset_server: Res<AssetServer>,
) {
Expand All @@ -61,7 +61,7 @@ fn setup(
{
spawn_birds(
&mut commands,
&window,
&windows,
&mut counter,
initial_count,
texture.clone_weak(),
Expand Down Expand Up @@ -126,7 +126,7 @@ fn mouse_handler(
mut commands: Commands,
time: Res<Time>,
mouse_button_input: Res<Input<MouseButton>>,
window: Res<WindowDescriptor>,
windows: Res<Windows>,
bird_texture: Res<BirdTexture>,
mut counter: ResMut<BevyCounter>,
) {
Expand All @@ -138,7 +138,7 @@ fn mouse_handler(
let spawn_count = (BIRDS_PER_SECOND as f64 * time.delta_seconds_f64()) as u128;
spawn_birds(
&mut commands,
&window,
&windows,
&mut counter,
spawn_count,
bird_texture.0.clone(),
Expand All @@ -148,13 +148,14 @@ fn mouse_handler(

fn spawn_birds(
commands: &mut Commands,
window: &WindowDescriptor,
windows: &Windows,
counter: &mut BevyCounter,
spawn_count: u128,
texture: Handle<Image>,
) {
let bird_x = (window.width / -2.) + HALF_BIRD_SIZE;
let bird_y = (window.height / 2.) - HALF_BIRD_SIZE;
let window = windows.get_primary().unwrap();
let bird_x = (window.width() as f32 / -2.) + HALF_BIRD_SIZE;
let bird_y = (window.height() as f32 / 2.) - HALF_BIRD_SIZE;
for count in 0..spawn_count {
let bird_z = (counter.count + count) as f32 * 0.00001;
commands
Expand Down Expand Up @@ -190,9 +191,10 @@ fn movement_system(time: Res<Time>, mut bird_query: Query<(&mut Bird, &mut Trans
}
}

fn collision_system(window: Res<WindowDescriptor>, mut bird_query: Query<(&mut Bird, &Transform)>) {
let half_width = window.width as f32 * 0.5;
let half_height = window.height as f32 * 0.5;
fn collision_system(windows: Res<Windows>, mut bird_query: Query<(&mut Bird, &Transform)>) {
let window = windows.get_primary().unwrap();
let half_width = window.width() as f32 * 0.5;
let half_height = window.height() as f32 * 0.5;

for (mut bird, transform) in bird_query.iter_mut() {
let x_vel = bird.velocity.x;
Expand Down

0 comments on commit d3749a9

Please sign in to comment.