-
Hello, I'm new to bevy and I'm using use bevy::prelude::*;
// A simple plugin
pub struct HelloPlugin;
impl Plugin for HelloPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(GreetTimer(Timer::from_seconds(2.0, TimerMode::Repeating)));
app.add_systems(Startup, hello_world);
app.add_systems(Update, (spawn_player, query_player).chain());
}
}
// a simple system
fn hello_world() {
println!("Hello, world!");
}
#[derive(Component)]
struct Name(String);
#[derive(Component)]
struct Hp(i32);
#[derive(Bundle)]
struct Player {
name: Name,
hp: Hp
}
// a simple system that adds 2 `player`s into the app
fn spawn_player(mut c: Commands) {
c.spawn(
Player {
name: Name("Player 1".to_string()),
hp: Hp(100)
}
);
c.spawn(
Player {
name: Name("Player 2".to_string()),
hp: Hp(100)
}
);
}
#[derive(Resource)]
struct GreetTimer(Timer);
fn query_player(time: Res<Time>, mut timer: ResMut<GreetTimer>, q: Query<&Name, With<Hp>>) {
if timer.0.tick(time.delta()).just_finished() {
for name in &q {
println!("{}", name.0);
}
}
}
fn main() {
App::new()
.add_plugins(HelloPlugin)
.run();
} |
Beta Was this translation helpful? Give feedback.
Answered by
anzhi0708
Apr 24, 2025
Replies: 1 comment
-
Problem solved by adding basic plugin fn main() {
App::new()
.add_plugins(MinimalPlugins) // +++
.add_plugins(HelloPlugin)
.run();
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
anzhi0708
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem solved by adding basic plugin