11 releases (6 stable)
2.0.0 | Mar 17, 2024 |
---|---|
1.0.4 | Dec 26, 2022 |
0.1.4 | Dec 23, 2022 |
#817 in Game dev
340 downloads per month
18KB
164 lines
Bevy ECS Markers
Adds the support for marking entites and fetching them in queries
Example
View more examples here
#[derive(EntityMarker)]
enum Players {
Red,
Blue,
Green,
Yellow,
}
#[derive(Component)]
struct Player {
field: usize,
}
fn main() {
App::new()
.add_plugins(LogPlugin::default())
.init_marker::<Players>()
.add_systems(Startup, (setup, move_red_player).chain())
.run();
}
fn setup(mut commands: Commands, mut players: MarkerMut<Players>) {
players[Players::Red].assign(commands.spawn(Player { field: 2 }).id());
players[Players::Blue].assign(commands.spawn(Player { field: 5 }).id());
players[Players::Green].assign(commands.spawn(Player { field: 7 }).id());
players[Players::Yellow].assign(commands.spawn(Player { field: 1 }).id());
}
fn move_red_player(mut query: Query<&mut Player>, current: Marker<Players>) {
let Ok(mut player) = query.get_mut(current[Players::Red].id()) else {
warn!("Red Player not set yet!");
return;
};
let old = player.field;
player.field += 2;
let new = player.field;
info!("Player moved from field {old} to field {new}");
}
License
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.
Dependencies
~9–36MB
~546K SLoC