diff --git a/src/hud.rs b/src/hud.rs new file mode 100644 index 0000000..8fabc71 --- /dev/null +++ b/src/hud.rs @@ -0,0 +1,68 @@ +use bevy::prelude::*; +use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin}; + +pub struct OutFlyHudPlugin; +impl Plugin for OutFlyHudPlugin { + fn build(&self, app: &mut App) { + app.add_systems(Startup, setup); + app.add_systems(Update, update); + app.insert_resource(FPSUpdateTimer(Timer::from_seconds(0.25, TimerMode::Repeating))); + } +} + +#[derive(Component)] +struct FpsText; + +#[derive(Resource)] +struct FPSUpdateTimer(Timer); + +fn setup( + mut commands: Commands, +) { + commands.spawn(( + TextBundle::from_sections([ + TextSection::new( + "FPS: ", + TextStyle { + //font: asset_server.load("fonts/FiraSans-Bold.ttf"), + font_size: 60.0, + ..default() + }, + ), + TextSection::from_style(if cfg!(feature = "default_font") { + TextStyle { + font_size: 60.0, + color: Color::GOLD, + ..default() + } + } else { + // "default_font" feature is unavailable, load a font to use instead. + TextStyle { + //font: asset_server.load("fonts/FiraMono-Medium.ttf"), + font_size: 60.0, + color: Color::GOLD, + ..default() + } + }), + ]), + FpsText, + )); +} + +fn update( + diagnostics: Res, + time:Res