feat: use some Bevy systems to print some messages

This commit is contained in:
Christopher Willis-Ford 2022-09-30 14:55:16 -07:00
parent 4274ec5373
commit dd577c6018

View file

@ -1,3 +1,30 @@
use bevy::prelude::*;
fn main() {
println!("Hello, world!");
App::new()
.add_startup_system(add_default_sprites)
.add_system(hello_world)
.add_system(print_sprite_names)
.run();
}
fn hello_world() {
println!("hello, world!");
}
#[derive(Component)]
struct Sprite;
#[derive(Component)]
struct Name(String);
fn add_default_sprites(mut commands: Commands) {
commands.spawn().insert(Sprite).insert(Name("Sprite 1".to_string()));
commands.spawn().insert(Sprite).insert(Name("Sprite 2".to_string()));
}
fn print_sprite_names(query: Query<&Name, With<Sprite>>) {
for name in query.iter() {
println!("found a sprite named {}", name.0);
}
}