Wire the 'Start' button to a state changer
This commit is contained in:
@@ -5,6 +5,8 @@ use bevy::{
|
|||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::GameState;
|
||||||
|
|
||||||
pub const BTN_BORDER_COLOR: Color = Color::WHITE;
|
pub const BTN_BORDER_COLOR: Color = Color::WHITE;
|
||||||
pub const BTN_BG_COLOR: Color = Color::BLACK;
|
pub const BTN_BG_COLOR: Color = Color::BLACK;
|
||||||
pub const BTN_BG_SELECTED: Color = bevy::prelude::Color::Srgba(DARK_GRAY);
|
pub const BTN_BG_SELECTED: Color = bevy::prelude::Color::Srgba(DARK_GRAY);
|
||||||
@@ -29,9 +31,11 @@ pub fn spawn_main_menu(mut commands: Commands) {
|
|||||||
TextShadow::default(),
|
TextShadow::default(),
|
||||||
));
|
));
|
||||||
let mut start_button = cmds.spawn(button_bundle("Start game"));
|
let mut start_button = cmds.spawn(button_bundle("Start game"));
|
||||||
start_button.observe(|_trigger: On<Pointer<Click>>| {
|
start_button.observe(
|
||||||
info!("The start button was pressed.");
|
|_trigger: On<Pointer<Click>>, mut game_state: ResMut<NextState<GameState>>| {
|
||||||
});
|
game_state.set(GameState::Playing);
|
||||||
|
},
|
||||||
|
);
|
||||||
let mut quit_button = cmds.spawn(button_bundle("Quit Game"));
|
let mut quit_button = cmds.spawn(button_bundle("Quit Game"));
|
||||||
quit_button.observe(
|
quit_button.observe(
|
||||||
|_trigger: On<Pointer<Click>>, mut messages: MessageWriter<AppExit>| {
|
|_trigger: On<Pointer<Click>>, mut messages: MessageWriter<AppExit>| {
|
||||||
|
|||||||
Reference in New Issue
Block a user