diff --git a/examples/2d/many_sprites.rs b/examples/2d/many_sprites.rs index 203efe376488f..a3ca208a34734 100644 --- a/examples/2d/many_sprites.rs +++ b/examples/2d/many_sprites.rs @@ -2,6 +2,7 @@ use bevy::{ diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, math::Quat, prelude::*, + render::camera::Camera, sprite::SpriteSettings, }; @@ -9,9 +10,6 @@ use rand::Rng; const CAMERA_SPEED: f32 = 1000.0; -pub struct PrintTimer(Timer); -pub struct Position(Transform); - /// This example is for performance testing purposes. /// See https://github.com/bevyengine/bevy/pull/1492 fn main() { @@ -24,8 +22,8 @@ fn main() { }) .add_plugins(DefaultPlugins) .add_startup_system(setup) - .add_system(tick.label("Tick")) - .add_system(move_camera.after("Tick")) + .add_system(tick_system.label("Tick")) + .add_system(move_camera_system.after("Tick")) .run() } @@ -44,14 +42,15 @@ fn setup( let sprite_handle = materials.add(assets.load("branding/icon.png").into()); + // Spawns the camera commands .spawn() .insert_bundle(OrthographicCameraBundle::new_2d()) - .insert(PrintTimer(Timer::from_seconds(1.0, true))) - .insert(Position(Transform::from_translation(Vec3::new( - 0.0, 0.0, 1000.0, - )))); + .insert(Timer::from_seconds(1.0, true)) + .insert(Transform::from_xyz(0.0, 0.0, 1000.0)); + // Builds and spawns the sprites + let mut sprites = vec![]; for y in -half_y..half_y { for x in -half_x..half_x { let position = Vec2::new(x as f32, y as f32); @@ -59,7 +58,7 @@ fn setup( let rotation = Quat::from_rotation_z(rng.gen::()); let scale = Vec3::splat(rng.gen::() * 2.0); - commands.spawn().insert_bundle(SpriteBundle { + sprites.push(SpriteBundle { material: sprite_handle.clone(), transform: Transform { translation, @@ -71,26 +70,23 @@ fn setup( }); } } + commands.spawn_batch(sprites); } -fn move_camera(time: Res