diff --git a/examples/games/game_menu.rs b/examples/games/game_menu.rs index 836748fa8b..ed541c1292 100644 --- a/examples/games/game_menu.rs +++ b/examples/games/game_menu.rs @@ -1,6 +1,18 @@ -//! This example will display a simple menu using Bevy UI where you can start a new game, -//! change some settings or quit. There is no actual game, it will just display the current -//! settings for 5 seconds before going back to the menu. +//! Many games need a "Menu" to change game settings (parameters that change sound, graphics, gameplay etc.) This example is a simple menu to navigate between and manipulate several options for a "game" that displays the options to us, with options represented in-engine with Resources. +//! +//! A "State" in game development is a broad-strokes way of saying "Certain things apply at this time that don't at other times." Very abstract! Being specific, we can use enum-based states in Bevy to control things like "are we in a menu or in-game?" or "are we in an overworld, inventory screen, or a battle?" +//! +//! Defining a state in Bevy involves creating an enum which implements [`States`], which we can derive alongside its other prerequisite traits, and then manually registering that state with the Bevy [`App`]. It's useful to also add a [`Default`] implementation for the state, but not necessary. +//! +//! Resources ([`Res`]/[`ResMut`]) are used to store and manipulate game options here, as these are one-off pieces of data that act as "global information" that will want to be accessed throughout the game, and not in one single state / substate. +//! +//! The [`Node`] component is a foundational part of UI in Bevy, it makes an entity act like (but not exactly like) an HTML tag with a `style` attribute. It has a lot of fields, but we can avoid having to declare all of them by defining the ones we're fine with being default with `..default()`. +//! +//! Like in many other game and UI frameworks, UI Hierarchies are a major part of how we make useful UI in Bevy. Building out a hierarchy involves spawning one or more "child" entities on an entity, and this can go arbitrarily deep! The easiest way to spawn children on an entity is with the [`children![]`][children] macro i.e. we can spawn a ui node with 2 children with `commands.spawn((Node::default(), /* non-child components */, children![Node::default(), (Node::default(), Name("This child node has extra components!".into()))])))`. +//! +//! [`Node`]s with [`Node`] children will use the layout information they're given (mostly in [`Node`]'s fields) to figure out how to look. There's separate styling rules for `Text` at this time. +//! +//! To make entering a state mean entities get spawned we need to add a system to the app that runs on a specific [`OnEnter(/* The relevant state */)`][OnEnter] Schedule. There's also [`OnExit(/* The relevant state */)`][OnExit] for whatever you want to do when a state exits. In this example [`OnExit`] is used to manually despawn state-specific entities but this can be automated with "State-scoped entities." use bevy::prelude::*;