maybe fix
This commit is contained in:
parent
1383ebfd05
commit
2f5358726b
@ -144,7 +144,7 @@ impl Game {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(mut self) {
|
pub fn run<F: Fn(&mut Context) -> ()>(mut self, f: F) {
|
||||||
'running: loop {
|
'running: loop {
|
||||||
for event in self.event_pump.poll_iter() {
|
for event in self.event_pump.poll_iter() {
|
||||||
match event {
|
match event {
|
||||||
@ -156,6 +156,9 @@ impl Game {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.canvas.set_draw_color(Color::RGB(60, 180, 180));
|
||||||
|
self.canvas.clear();
|
||||||
|
f(&mut self.context());
|
||||||
self.canvas.present();
|
self.canvas.present();
|
||||||
}
|
}
|
||||||
self.canvas.present();
|
self.canvas.present();
|
||||||
|
10
src/main.rs
10
src/main.rs
@ -12,7 +12,7 @@ impl<'a> Component for Player<'a> {}
|
|||||||
struct PlayerRenderer;
|
struct PlayerRenderer;
|
||||||
|
|
||||||
impl System for PlayerRenderer {
|
impl System for PlayerRenderer {
|
||||||
fn on_add(&self, ctx: &mut engine::Context) {}
|
fn on_add(&self, _ctx: &mut engine::Context) {}
|
||||||
|
|
||||||
fn on_update(&self, _ctx: &mut engine::Context) {}
|
fn on_update(&self, _ctx: &mut engine::Context) {}
|
||||||
}
|
}
|
||||||
@ -24,10 +24,10 @@ fn main() {
|
|||||||
let mut context = game.context();
|
let mut context = game.context();
|
||||||
context.add_system(Box::new(PlayerRenderer));
|
context.add_system(Box::new(PlayerRenderer));
|
||||||
context.spawn(vec![Box::new(Player { sprite: None })]);
|
context.spawn(vec![Box::new(Player { sprite: None })]);
|
||||||
|
|
||||||
let sprite = context.load_sprite("textures/player.png").unwrap();
|
|
||||||
context.draw_sprite(&sprite, 16, 16).unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
game.run();
|
game.run(|context| {
|
||||||
|
let sprite = context.load_sprite("textures/player.png").unwrap();
|
||||||
|
context.draw_sprite(&sprite, 16, 16).unwrap();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user