Add ability to set drawing colour
This commit is contained in:
parent
a2068344d1
commit
32921cd14f
|
@ -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<Window>,
|
||||
texture_creator: TextureCreator<WindowContext>,
|
||||
|
@ -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.
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue