maybe fix

This commit is contained in:
SimonFJ20 2024-04-01 22:15:31 +02:00
parent 1383ebfd05
commit 2f5358726b
2 changed files with 9 additions and 6 deletions

View File

@ -144,7 +144,7 @@ impl Game {
})
}
pub fn run(mut self) {
pub fn run<F: Fn(&mut Context) -> ()>(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();

View File

@ -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 })]);
}
game.run(|context| {
let sprite = context.load_sprite("textures/player.png").unwrap();
context.draw_sprite(&sprite, 16, 16).unwrap();
}
game.run();
});
}