mirror of
https://github.com/bevyengine/bevy
synced 2024-11-27 15:10:19 +00:00
6d6bc2a8b4
This is extracted out of eb8f973646476b4a4926ba644a77e2b3a5772159 and includes some additional changes to remove all references to AppBuilder and fix examples that still used App::build() instead of App::new(). In addition I didn't extract the sub app feature as it isn't ready yet. You can use `git diff --diff-filter=M eb8f973646476b4a4926ba644a77e2b3a5772159` to find all differences in this PR. The `--diff-filtered=M` filters all files added in the original commit but not in this commit away. Co-Authored-By: Carter Anderson <mcanders1@gmail.com>
89 lines
2.2 KiB
Rust
89 lines
2.2 KiB
Rust
use bevy::{
|
|
input::{
|
|
keyboard::KeyboardInput,
|
|
mouse::{MouseButtonInput, MouseMotion, MouseWheel},
|
|
},
|
|
prelude::*,
|
|
};
|
|
|
|
fn main() {
|
|
App::new()
|
|
.insert_resource(WindowDescriptor {
|
|
width: 300.,
|
|
height: 300.,
|
|
..Default::default()
|
|
})
|
|
.add_plugins(DefaultPlugins)
|
|
// One time greet
|
|
.add_startup_system(hello_wasm_system.system())
|
|
// Track ticks (sanity check, whether game loop is running)
|
|
.add_system(counter.system())
|
|
// Track input events
|
|
.add_system(track_input_events.system())
|
|
.run();
|
|
}
|
|
|
|
fn hello_wasm_system() {
|
|
info!("hello wasm");
|
|
}
|
|
|
|
fn counter(mut state: Local<CounterState>, time: Res<Time>) {
|
|
if state.count % 60 == 0 {
|
|
info!(
|
|
"tick {} @ {:?} [Δ{}]",
|
|
state.count,
|
|
time.time_since_startup(),
|
|
time.delta_seconds()
|
|
);
|
|
}
|
|
state.count += 1;
|
|
}
|
|
|
|
#[derive(Default)]
|
|
struct CounterState {
|
|
count: u32,
|
|
}
|
|
|
|
fn track_input_events(
|
|
mut ev_keys: EventReader<KeyboardInput>,
|
|
mut ev_cursor: EventReader<CursorMoved>,
|
|
mut ev_motion: EventReader<MouseMotion>,
|
|
mut ev_mousebtn: EventReader<MouseButtonInput>,
|
|
mut ev_scroll: EventReader<MouseWheel>,
|
|
) {
|
|
// Keyboard input
|
|
for ev in ev_keys.iter() {
|
|
if ev.state.is_pressed() {
|
|
info!("Just pressed key: {:?}", ev.key_code);
|
|
} else {
|
|
info!("Just released key: {:?}", ev.key_code);
|
|
}
|
|
}
|
|
|
|
// Absolute cursor position (in window coordinates)
|
|
for ev in ev_cursor.iter() {
|
|
info!("Cursor at: {}", ev.position);
|
|
}
|
|
|
|
// Relative mouse motion
|
|
for ev in ev_motion.iter() {
|
|
info!("Mouse moved {} pixels", ev.delta);
|
|
}
|
|
|
|
// Mouse buttons
|
|
for ev in ev_mousebtn.iter() {
|
|
if ev.state.is_pressed() {
|
|
info!("Just pressed mouse button: {:?}", ev.button);
|
|
} else {
|
|
info!("Just released mouse button: {:?}", ev.button);
|
|
}
|
|
}
|
|
|
|
// scrolling (mouse wheel, touchpad, etc.)
|
|
for ev in ev_scroll.iter() {
|
|
info!(
|
|
"Scrolled vertically by {} and horizontally by {}.",
|
|
ev.y, ev.x
|
|
);
|
|
}
|
|
}
|