 81b53d15d4
			
		
	
	
		81b53d15d4
		
	
	
	
	
		
			
			Resolves #1253 #1562 This makes the Commands apis consistent with World apis. This moves to a "type state" pattern (like World) where the "current entity" is stored in an `EntityCommands` builder. In general this tends to cuts down on indentation and line count. It comes at the cost of needing to type `commands` more and adding more semicolons to terminate expressions. I also added `spawn_bundle` to Commands because this is a common enough operation that I think its worth providing a shorthand.
		
			
				
	
	
		
			40 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| use bevy::prelude::*;
 | |
| 
 | |
| fn main() {
 | |
|     App::build()
 | |
|         .add_plugins(DefaultPlugins)
 | |
|         .add_startup_system(setup.system())
 | |
|         .add_system(animate.system())
 | |
|         .run();
 | |
| }
 | |
| 
 | |
| fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
 | |
|     // 2d camera
 | |
|     commands.spawn_bundle(OrthographicCameraBundle::new_2d());
 | |
|     commands.spawn_bundle(Text2dBundle {
 | |
|         text: Text::with_section(
 | |
|             "This text is in the 2D scene.",
 | |
|             TextStyle {
 | |
|                 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
 | |
|                 font_size: 60.0,
 | |
|                 color: Color::WHITE,
 | |
|             },
 | |
|             TextAlignment {
 | |
|                 vertical: VerticalAlign::Center,
 | |
|                 horizontal: HorizontalAlign::Center,
 | |
|             },
 | |
|         ),
 | |
|         ..Default::default()
 | |
|     });
 | |
| }
 | |
| 
 | |
| fn animate(time: Res<Time>, mut query: Query<&mut Transform, With<Text>>) {
 | |
|     // `Transform.translation` will determine the location of the text.
 | |
|     // `Transform.scale` and `Transform.rotation` do not yet affect text (though you can set the
 | |
|     // size of the text via `Text.style.font_size`)
 | |
|     for mut transform in query.iter_mut() {
 | |
|         transform.translation.x = 100.0 * time.seconds_since_startup().sin() as f32;
 | |
|         transform.translation.y = 100.0 * time.seconds_since_startup().cos() as f32;
 | |
|     }
 | |
| }
 |