clear_color/clear_color.rs
1//! Shows how to set the solid color that is used to paint the window before the frame gets drawn.
2//!
3//! Acts as background color, since pixels that are not drawn in a frame remain unchanged.
4
5use bevy::{color::palettes::css::PURPLE, prelude::*};
6
7fn main() {
8 App::new()
9 .insert_resource(ClearColor(Color::srgb(0.5, 0.5, 0.9)))
10 .add_plugins(DefaultPlugins)
11 .add_systems(Startup, setup)
12 .add_systems(Update, change_clear_color)
13 .run();
14}
15
16fn setup(mut commands: Commands) {
17 commands.spawn(Camera2d);
18}
19
20fn change_clear_color(input: Res<ButtonInput<KeyCode>>, mut clear_color: ResMut<ClearColor>) {
21 if input.just_pressed(KeyCode::Space) {
22 clear_color.0 = PURPLE.into();
23 }
24}