From ad20a2771d3169c3643fa8c7d3272f1fe1a8df14 Mon Sep 17 00:00:00 2001 From: Yash Karandikar Date: Wed, 11 May 2022 13:34:34 -0500 Subject: [PATCH] Add ability to set a Sprite's position --- src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 9ecd00c..0487665 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -272,6 +272,17 @@ impl Sprite { self.rect.set_y(new_y); } + /// Reposition the center of the sprite in the form of (x, y) + /// + /// ``` + /// # use cat_box::*; + /// # let mut s = Sprite::new("duck.png", 500, 400).unwrap(); + /// s.set_position((5, 10)); + /// ``` + pub fn set_position(&mut self, position: (i32, i32)) { + self.rect.center_on(position); + } + /// Set the angle of the sprite, in degrees of clockwise rotation. /// /// ```