Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/examples/window/clear_color.rs
6595 views
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
5
use bevy::{color::palettes::css::PURPLE, prelude::*};
6
7
fn 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
16
fn setup(mut commands: Commands) {
17
commands.spawn(Camera2d);
18
}
19
20
fn 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
}
25
26