fix: menu, character despawn
This commit is contained in:
parent
d109225da6
commit
a52a3b84c8
4 changed files with 44 additions and 25 deletions
41
src/menu.rs
41
src/menu.rs
|
|
@ -3,33 +3,42 @@ use crate::AppState;
|
|||
use bevy::{
|
||||
input::{keyboard::KeyCode, Input},
|
||||
prelude::*,
|
||||
sprite::MaterialMesh2dBundle,
|
||||
};
|
||||
|
||||
pub struct MenuPlugin;
|
||||
|
||||
#[derive(Component)]
|
||||
struct Menu();
|
||||
|
||||
impl Plugin for MenuPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_system_set(SystemSet::on_enter(AppState::Menu).with_system(setup))
|
||||
.add_system_set(
|
||||
SystemSet::on_update(AppState::Menu).with_system(keyboard_input_system),
|
||||
);
|
||||
.add_system_set(SystemSet::on_update(AppState::Menu).with_system(keyboard_input_system))
|
||||
.add_system_set(SystemSet::on_exit(AppState::Menu).with_system(despawn));
|
||||
}
|
||||
}
|
||||
|
||||
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
commands.spawn_bundle(Text2dBundle {
|
||||
text: Text::from_section(
|
||||
"Press ENTER",
|
||||
TextStyle {
|
||||
font: asset_server.get_handle("Cantarell-VF.odt"),
|
||||
font_size: 64.0,
|
||||
color: Color::WHITE,
|
||||
},
|
||||
)
|
||||
.with_alignment(TextAlignment::CENTER),
|
||||
..Default::default()
|
||||
});
|
||||
commands
|
||||
.spawn_bundle(Text2dBundle {
|
||||
text: Text::from_section(
|
||||
"Press ENTER",
|
||||
TextStyle {
|
||||
font: asset_server.get_handle("Cantarell-VF.otf"),
|
||||
font_size: 64.0,
|
||||
color: Color::WHITE,
|
||||
},
|
||||
)
|
||||
.with_alignment(TextAlignment::CENTER),
|
||||
..Default::default()
|
||||
})
|
||||
.insert(Menu());
|
||||
}
|
||||
|
||||
fn despawn(mut commands: Commands, menu_query: Query<Entity, With<Menu>>) {
|
||||
for entity in menu_query.iter() {
|
||||
commands.entity(entity).despawn_recursive();
|
||||
}
|
||||
}
|
||||
|
||||
fn keyboard_input_system(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue