2020-10-06 13:08:12 -07:00
|
|
|
use bevy::prelude::*;
|
2020-07-20 02:05:56 -07:00
|
|
|
|
2020-07-28 13:43:07 -07:00
|
|
|
/// This example illustrates how to customize the default window settings
|
2020-07-20 02:05:56 -07:00
|
|
|
fn main() {
|
2021-04-11 13:13:07 -07:00
|
|
|
App::new()
|
2021-01-30 15:55:13 -05:00
|
|
|
.insert_resource(WindowDescriptor {
|
2020-07-20 02:05:56 -07:00
|
|
|
title: "I am a window!".to_string(),
|
2020-12-13 15:05:56 -08:00
|
|
|
width: 500.,
|
|
|
|
height: 300.,
|
2020-07-20 02:05:56 -07:00
|
|
|
vsync: true,
|
2020-08-13 10:47:40 +02:00
|
|
|
..Default::default()
|
2020-07-20 02:05:56 -07:00
|
|
|
})
|
2020-11-02 19:01:17 -08:00
|
|
|
.add_plugins(DefaultPlugins)
|
2021-09-14 06:14:19 +00:00
|
|
|
.add_system(change_title)
|
|
|
|
.add_system(toggle_cursor)
|
2020-07-20 02:05:56 -07:00
|
|
|
.run();
|
|
|
|
}
|
2020-10-15 20:42:19 +02:00
|
|
|
|
|
|
|
/// This system will then change the title during execution
|
|
|
|
fn change_title(time: Res<Time>, mut windows: ResMut<Windows>) {
|
|
|
|
let window = windows.get_primary_mut().unwrap();
|
|
|
|
window.set_title(format!(
|
|
|
|
"Seconds since startup: {}",
|
2020-11-28 16:08:31 -05:00
|
|
|
time.seconds_since_startup().round()
|
2020-10-15 20:42:19 +02:00
|
|
|
));
|
|
|
|
}
|
2020-10-16 17:07:01 -04:00
|
|
|
|
|
|
|
/// This system toggles the cursor's visibility when the space bar is pressed
|
|
|
|
fn toggle_cursor(input: Res<Input<KeyCode>>, mut windows: ResMut<Windows>) {
|
|
|
|
let window = windows.get_primary_mut().unwrap();
|
|
|
|
if input.just_pressed(KeyCode::Space) {
|
|
|
|
window.set_cursor_lock_mode(!window.cursor_locked());
|
|
|
|
window.set_cursor_visibility(!window.cursor_visible());
|
|
|
|
}
|
|
|
|
}
|