diff --git a/src/lib.rs b/src/lib.rs index ebaf0df..4e2b8e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -235,7 +235,7 @@ impl Sprite { /// Game context. /// -/// This should never actually be used; instead, just pass it around to the various cat-box functions such as [`Sprite::draw()`]. +/// In most cases, this should never actually be used; instead, just pass it around to the various cat-box functions such as [`Sprite::draw()`]. pub struct Context { canvas: Canvas, texture_creator: TextureCreator, @@ -264,6 +264,11 @@ impl Context { fn clear(&mut self) { self.canvas.clear(); } + + /// Set the background colour. See [`Canvas::set_draw_color()`](sdl2::render::Canvas::set_draw_color()) for more info. + pub fn set_background_colour(&mut self, r: u8, g: u8, b: u8) { + self.canvas.set_draw_color(Color::RGB(r, g, b)); + } } /// Representation of the game. diff --git a/src/main.rs b/src/main.rs index ee41e71..a83f14e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ fn main() { let mut s2 = Sprite::new("duck.png", 400, 500).unwrap(); game.run(|ctx, event_pump| { i = (i + 1.0) % 360.0; + ctx.set_background_colour(i as u8, 64, 255); let (start_x, start_y) = s.position(); let m = sdl2::mouse::MouseState::new(event_pump.as_ref());