finish getting started guide

This commit is contained in:
OMGeeky
2025-04-13 14:32:51 +02:00
parent b8646f5a1a
commit 6347b4f4ff

View File

@@ -24,13 +24,15 @@ fn add_people(mut commands: Commands) {
commands.spawn((Person, Name("Renzo Hume".to_string())));
commands.spawn((Person, Name("Zayna Nieves".to_string())));
}
#[derive(Component)]
#[derive(Resource)]
struct GreetTimer(Timer);
//endregion
//region query
fn greet_people(query: Query<&Name, With<Person>>) {
for name in &query {
println!("hello {}!", name.0);
fn greet_people(time: Res<Time>, mut timer: ResMut<GreetTimer>, query: Query<&Name, With<Person>>) {
if timer.0.tick(time.delta()).just_finished() {
for name in &query {
println!("hello {}!", name.0);
}
}
}
fn update_people(mut query: Query<&mut Name, With<Person>>) {
@@ -46,8 +48,9 @@ fn update_people(mut query: Query<&mut Name, With<Person>>) {
pub struct HelloPlugin;
impl Plugin for HelloPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, add_people)
.add_systems(Update, (hello_world, (update_people, greet_people).chain()));
app.insert_resource(GreetTimer(Timer::from_seconds(2.0, TimerMode::Repeating)))
.add_systems(Startup, add_people)
.add_systems(Update, ((update_people, greet_people).chain()));
}
}
//endregion