2020-05-18 01:09:29 +00:00
|
|
|
use bevy::{
|
|
|
|
diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin},
|
|
|
|
prelude::*,
|
|
|
|
};
|
2020-05-13 20:09:32 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
App::build()
|
|
|
|
.add_default_plugins()
|
2020-05-18 01:09:29 +00:00
|
|
|
.add_plugin(FrameTimeDiagnosticsPlugin::default())
|
2020-05-14 00:31:56 +00:00
|
|
|
.add_startup_system(setup.system())
|
2020-06-17 20:27:10 +00:00
|
|
|
.add_system(text_update_system.system())
|
2020-05-13 20:09:32 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2020-06-27 19:06:12 +00:00
|
|
|
fn text_update_system(
|
|
|
|
diagnostics: Res<Diagnostics>,
|
|
|
|
world: &mut SubWorld,
|
|
|
|
query: &mut Query<Write<Label>>,
|
|
|
|
) {
|
|
|
|
for mut label in query.iter_mut(world) {
|
|
|
|
if let Some(fps) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) {
|
|
|
|
if let Some(average) = fps.average() {
|
|
|
|
label.text = format!("FPS: {:.2}", average);
|
|
|
|
}
|
2020-05-18 21:53:57 +00:00
|
|
|
}
|
2020-05-18 01:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-13 20:09:32 +00:00
|
|
|
|
2020-06-27 17:18:27 +00:00
|
|
|
fn setup(asset_server: Res<AssetServer>, command_buffer: &mut CommandBuffer) {
|
2020-05-18 01:09:29 +00:00
|
|
|
let font_handle = asset_server.load("assets/fonts/FiraSans-Bold.ttf").unwrap();
|
2020-05-14 00:31:56 +00:00
|
|
|
command_buffer
|
2020-05-13 20:09:32 +00:00
|
|
|
.build()
|
|
|
|
// 2d camera
|
2020-06-27 17:20:26 +00:00
|
|
|
.entity_with(OrthographicCameraComponents::default())
|
2020-05-13 20:09:32 +00:00
|
|
|
// texture
|
2020-06-25 18:21:56 +00:00
|
|
|
.entity_with(LabelComponents {
|
2020-06-27 19:06:12 +00:00
|
|
|
node: Node::new(Anchors::TOP_LEFT, Margins::new(0.0, 250.0, 0.0, 60.0)),
|
2020-05-18 01:09:29 +00:00
|
|
|
label: Label {
|
|
|
|
text: "FPS:".to_string(),
|
|
|
|
font: font_handle,
|
2020-06-14 01:53:31 +00:00
|
|
|
style: TextStyle {
|
|
|
|
font_size: 60.0,
|
|
|
|
color: Color::WHITE,
|
|
|
|
},
|
2020-05-18 01:09:29 +00:00
|
|
|
},
|
2020-05-13 20:09:32 +00:00
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
}
|