2020-10-06 20:08:12 +00:00
|
|
|
use bevy::prelude::*;
|
2020-07-20 09:05:56 +00:00
|
|
|
|
2020-07-28 20:43:07 +00:00
|
|
|
/// This example illustrates how to customize the default window settings
|
2020-07-20 09:05:56 +00:00
|
|
|
fn main() {
|
|
|
|
App::build()
|
2021-01-30 20:55:13 +00:00
|
|
|
.insert_resource(WindowDescriptor {
|
2020-07-20 09:05:56 +00:00
|
|
|
title: "I am a window!".to_string(),
|
2020-12-13 23:05:56 +00:00
|
|
|
width: 500.,
|
|
|
|
height: 300.,
|
2020-07-20 09:05:56 +00:00
|
|
|
vsync: true,
|
2020-08-13 08:47:40 +00:00
|
|
|
..Default::default()
|
2020-07-20 09:05:56 +00:00
|
|
|
})
|
2020-11-03 03:01:17 +00:00
|
|
|
.add_plugins(DefaultPlugins)
|
2020-12-16 05:57:16 +00:00
|
|
|
.add_system(change_title.system())
|
|
|
|
.add_system(toggle_cursor.system())
|
2020-07-20 09:05:56 +00:00
|
|
|
.run();
|
|
|
|
}
|
2020-10-15 18:42:19 +00: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 21:08:31 +00:00
|
|
|
time.seconds_since_startup().round()
|
2020-10-15 18:42:19 +00:00
|
|
|
));
|
|
|
|
}
|
2020-10-16 21:07:01 +00: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());
|
|
|
|
}
|
|
|
|
}
|