game states cleanup
This commit is contained in:
+9
-1
@@ -57,11 +57,19 @@ fn spawn_chunk(commands: &mut Commands, id: i64, run_seed: u64) {
|
||||
crate::background::spawn_background_chunk(commands, id);
|
||||
// crate::obstacle::spawn_obstacle_chunk(commands, id, run_seed);
|
||||
}
|
||||
|
||||
fn cleanup_chunk(mut commands: Commands, entities: Query<Entity, With<Chunk>>) {
|
||||
for entity in entities {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorldPlugin;
|
||||
|
||||
impl Plugin for WorldPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(RunSeed(rand::random::<u64>()))
|
||||
.add_systems(Update, stream_world.run_if(in_state(GameState::InGame)));
|
||||
.add_systems(Update, stream_world.run_if(in_state(GameState::InGame)))
|
||||
.add_systems(OnExit(GameState::InGame), cleanup_chunk);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user