ui/text example: Use a unit component to identify the target Text (#612)
This commit is contained in:
		
							parent
							
								
									125afb41ac
								
							
						
					
					
						commit
						d61a1735e9
					
				| @ -13,8 +13,11 @@ fn main() { | |||||||
|         .run(); |         .run(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn text_update_system(diagnostics: Res<Diagnostics>, mut query: Query<&mut Text>) { | // A unit struct to help identify the FPS UI component, since there may be many Text components
 | ||||||
|     for mut text in &mut query.iter() { | 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(fps) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) { | ||||||
|             if let Some(average) = fps.average() { |             if let Some(average) = fps.average() { | ||||||
|                 text.value = format!("FPS: {:.2}", average); |                 text.value = format!("FPS: {:.2}", average); | ||||||
| @ -43,5 +46,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | |||||||
|                 }, |                 }, | ||||||
|             }, |             }, | ||||||
|             ..Default::default() |             ..Default::default() | ||||||
|         }); |         }) | ||||||
|  |         .with(FpsText); | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Zach Gotsch
						Zach Gotsch