2024-03-11 19:26:14 +00:00
|
|
|
//! Showcase how to use and configure FPS overlay.
|
|
|
|
|
|
|
|
use bevy::{
|
|
|
|
dev_tools::fps_overlay::{FpsOverlayConfig, FpsOverlayPlugin},
|
|
|
|
prelude::*,
|
|
|
|
};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
App::new()
|
|
|
|
.add_plugins((
|
|
|
|
DefaultPlugins,
|
|
|
|
FpsOverlayPlugin {
|
|
|
|
config: FpsOverlayConfig {
|
|
|
|
text_config: TextStyle {
|
|
|
|
// Here we define size of our overlay
|
2024-09-16 23:14:37 +00:00
|
|
|
font_size: 42.0,
|
2024-03-11 19:26:14 +00:00
|
|
|
// We can also change color of the overlay
|
|
|
|
color: Color::srgb(0.0, 1.0, 0.0),
|
|
|
|
// If we want, we can use a custom font
|
|
|
|
font: default(),
|
|
|
|
},
|
2024-09-17 15:16:28 +00:00
|
|
|
enabled: true,
|
2024-03-11 19:26:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
))
|
|
|
|
.add_systems(Startup, setup)
|
|
|
|
.add_systems(Update, customize_config)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn setup(mut commands: Commands) {
|
2024-03-20 13:11:48 +00:00
|
|
|
// We need to spawn a camera (2d or 3d) to see the overlay
|
2024-10-05 01:59:52 +00:00
|
|
|
commands.spawn(Camera2d);
|
2024-03-20 13:11:48 +00:00
|
|
|
|
|
|
|
// Instruction text
|
|
|
|
commands
|
|
|
|
.spawn(NodeBundle {
|
|
|
|
style: Style {
|
|
|
|
width: Val::Percent(100.0),
|
|
|
|
height: Val::Percent(100.0),
|
|
|
|
align_items: AlignItems::Center,
|
|
|
|
justify_content: JustifyContent::Center,
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
..default()
|
|
|
|
})
|
|
|
|
.with_children(|c| {
|
|
|
|
c.spawn(TextBundle::from_section(
|
|
|
|
concat!(
|
|
|
|
"Press 1 to change color of the overlay.\n",
|
2024-09-17 15:16:28 +00:00
|
|
|
"Press 2 to change size of the overlay.\n",
|
|
|
|
"Press 3 to toggle the overlay."
|
2024-03-20 13:11:48 +00:00
|
|
|
),
|
2024-09-16 23:14:37 +00:00
|
|
|
TextStyle::default(),
|
2024-03-20 13:11:48 +00:00
|
|
|
));
|
|
|
|
});
|
2024-03-11 19:26:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn customize_config(input: Res<ButtonInput<KeyCode>>, mut overlay: ResMut<FpsOverlayConfig>) {
|
|
|
|
if input.just_pressed(KeyCode::Digit1) {
|
|
|
|
// Changing resource will affect overlay
|
|
|
|
overlay.text_config.color = Color::srgb(1.0, 0.0, 0.0);
|
|
|
|
}
|
|
|
|
if input.just_pressed(KeyCode::Digit2) {
|
|
|
|
overlay.text_config.font_size -= 2.0;
|
|
|
|
}
|
2024-09-17 15:16:28 +00:00
|
|
|
if input.just_pressed(KeyCode::Digit3) {
|
|
|
|
overlay.enabled = !overlay.enabled;
|
|
|
|
}
|
2024-03-11 19:26:14 +00:00
|
|
|
}
|