mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
add basic example of a custom update loop (#799)
This commit is contained in:
parent
b324f66135
commit
31a433b69e
2 changed files with 35 additions and 0 deletions
|
@ -148,6 +148,10 @@ path = "examples/3d/texture.rs"
|
|||
name = "z_sort_debug"
|
||||
path = "examples/3d/z_sort_debug.rs"
|
||||
|
||||
[[example]]
|
||||
name = "custom_loop"
|
||||
path = "examples/app/custom_loop.rs"
|
||||
|
||||
[[example]]
|
||||
name = "empty_defaults"
|
||||
path = "examples/app/empty_defaults.rs"
|
||||
|
|
31
examples/app/custom_loop.rs
Normal file
31
examples/app/custom_loop.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
use bevy::prelude::*;
|
||||
use std::{io, io::BufRead};
|
||||
|
||||
struct Input(String);
|
||||
|
||||
/// This example demonstrates you can create a custom runner (to update an app manually). It reads
|
||||
/// lines from stdin and prints them from within the ecs.
|
||||
fn my_runner(mut app: App) {
|
||||
app.initialize();
|
||||
|
||||
println!("Type stuff into the console");
|
||||
for line in io::stdin().lock().lines() {
|
||||
{
|
||||
let mut input = app.resources.get_mut::<Input>().unwrap();
|
||||
input.0 = line.unwrap();
|
||||
}
|
||||
app.update();
|
||||
}
|
||||
}
|
||||
|
||||
fn print_system(input: Res<Input>) {
|
||||
println!("You typed: {}", input.0);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
App::build()
|
||||
.add_resource(Input(String::new()))
|
||||
.set_runner(my_runner)
|
||||
.add_system(print_system.system())
|
||||
.run();
|
||||
}
|
Loading…
Reference in a new issue