-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement pausing #206
Comments
Recently used this template for a game jam, and this was the one thing I felt was missing / was wrong from the template. I think the screen state should probably be a stack! If you want to pause the game you should push a pause state on top of the stack. If you then want to navigate to a settings menu you can push that as well on top of the stack. Then by leaving the settings menu you just pop it from the stack, and then to leave the pause state you pop it from the stack. That way you can re-use a settings menu from both the start screen and from a main menu (without having any special logic in the settings menu).
The Esc-button should always pop the top of the stack if there is more than one item on the stack. Game logic needs a Additionally it would be practical if the template implemented a "Backdrop" component (something that fills the entire screen, is black and transparent) that can render over the game but under any menus. This would also mean that you should probably have a This pattern will also capture the use-case that is if you are making a single player game and want the game to pause while you are in an inventory screen (or map screen, or upgrade screen, or shop screen, etc). And can support arbitrarily deep menus without any special code. |
|
Would it work to create your own type using a resource that tracks the stack. And two states that track the top and bottom of the stack with a system that syncs the two states with the state of the stack? Either that or just not use |
Yeah, in my own project I would agree. The (not-yet-fully-codified) design principles of this template include 1. not using any 3rd-party dependencies besides Improving |
Feels like being able to support both a pause state and a nested settings menu is strictly necessary, but I do get your point. Personally I think the template should take on the necessary complexity to support at least as much. I'd be happy to make PR, but I won't bother spending time on it if you're unlikely accept it. |
@TheKnarf I would not submit a PR for this yet in your position. I'll keep this in the back of my mind though and talk about it at some point with the Bevy maintainers. I also want to see a nested settings menu supported, and if the others agree, we may really need a stack. |
I feel like we could get most of the way with just sub-states (although it may be a little ugly). For instance here is a quick attempt at a pause screen main...will-hart:bevy_quickstart:pause-state |
@will-hart can I be inside multiple substates of the playing screen at once? |
If they're different types then yes. Keep in mind a pause menu is actually two features though, pausing the game and opening a menu, which should use orthogonal state types. |
How this can be implemented:
struct Pause(bool)
somewhere (core/pause.rs
if we hadcore/
, otherwise probably justsrc/pause.rs
or I guesssrc/lib.rs
)..run_if(not(in_state(Paused(true))))
on a case-by-case basis (this could be made more ergonomic with a custom run condition or system set provided inpause.rs
).Screen::Playing
, and togglePause
when you enter / exit that state. In my jam game I had anenum PlayingMenu { Pause, LevelUp, ... }
.The text was updated successfully, but these errors were encountered: