Crates.io | bevy_state_stack |
lib.rs | bevy_state_stack |
version | 0.2.1 |
source | src |
created_at | 2022-09-06 15:01:13.871085 |
updated_at | 2022-09-15 13:10:41.562035 |
description | An improved state stack for bevy. |
homepage | |
repository | https://gitlab.com/martintrumann/bevy_state_stack |
max_upload_size | |
id | 659573 |
size | 13,384 |
This crate allows you to use a state stack that is not confined to a single stage.
bevy version | bevy_state_stack version |
---|---|
0.8 | 0.1, 0.2 |
You're better off importing the entire library.
use bevy_state_stack::*;
Add the state enum into the app.
app.add_state_stack(AppState::Menu)
Add different systems to the app.
app.add_system_on_enter(AppState::Menu, setup_menu)
.add_system_on_exit(AppState::Menu, despawn::<Menu>)
.add_system_on_enter(AppState::Map, setup_map)
.add_system_on_update(AppState::Map, pause)
.add_system_on_update(AppState::Encounter, pause)
.add_system_set_on_update(
AppState::Menu,
SystemSet::new()
.with_system(resume)
.with_system(start_game),
)
You can set, push, or pop the state on top of the stack
by inserting the Stack
resource.
fn start_game(mut c: Commands) {
c.insert_resource(Stack::Set(AppState::Map))
}
fn pause(mut c: Commands) {
c.insert_resource(Stack::Push(AppState::Menu))
}
fn resume(mut c: Commands) {
c.insert_resource(Stack::<AppState>::Pop);
}