Crates.io | bevy_ecs_markers |
lib.rs | bevy_ecs_markers |
version | 2.0.0 |
source | src |
created_at | 2022-12-18 19:03:43.501368 |
updated_at | 2024-03-17 18:52:19.449194 |
description | 🏷️ Markers for Bevy ECS Entities |
homepage | |
repository | https://github.com/ChoppedStudio/bevy_ecs_markers |
max_upload_size | |
id | 740547 |
size | 57,543 |
Adds the support for marking entites and fetching them in queries
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}");
}
at your option.