diff --git a/src/engine.rs b/src/engine.rs index bb1f2d5..8e529d8 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -144,7 +144,7 @@ impl Game { }) } - pub fn run(mut self) { + pub fn run ()>(mut self, f: F) { 'running: loop { for event in self.event_pump.poll_iter() { 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(); diff --git a/src/main.rs b/src/main.rs index 3c6f0a5..c2c5922 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ impl<'a> Component for Player<'a> {} struct 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) {} } @@ -24,10 +24,10 @@ fn main() { let mut context = game.context(); context.add_system(Box::new(PlayerRenderer)); 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(); + }); }