mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 14:10:19 +00:00
ui/text example: Use a unit component to identify the target Text (#612)
This commit is contained in:
parent
125afb41ac
commit
d61a1735e9
1 changed files with 7 additions and 3 deletions
|
@ -13,8 +13,11 @@ fn main() {
|
|||
.run();
|
||||
}
|
||||
|
||||
fn text_update_system(diagnostics: Res<Diagnostics>, mut query: Query<&mut Text>) {
|
||||
for mut text in &mut query.iter() {
|
||||
// A unit struct to help identify the FPS UI component, since there may be many Text components
|
||||
struct FpsText;
|
||||
|
||||
fn text_update_system(diagnostics: Res<Diagnostics>, mut query: Query<(&mut Text, &FpsText)>) {
|
||||
for (mut text, _tag) in &mut query.iter() {
|
||||
if let Some(fps) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) {
|
||||
if let Some(average) = fps.average() {
|
||||
text.value = format!("FPS: {:.2}", average);
|
||||
|
@ -43,5 +46,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
},
|
||||
},
|
||||
..Default::default()
|
||||
});
|
||||
})
|
||||
.with(FpsText);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue