pub struct Sprite {
pub rect: Rect,
/* private fields */
}
Expand description
Representation of a sprite.
Fields
rect: Rect
Implementations
sourceimpl Sprite
impl Sprite
sourcepub fn new<P: AsRef<Path>>(path: P, x: i32, y: i32) -> Result<Self>
pub fn new<P: AsRef<Path>>(path: P, x: i32, y: i32) -> Result<Self>
Create a new Sprite. The path
is relative to the current directory while running.
Don’t forget to call draw()
after this.
let s = Sprite::new("duck.png", 500, 400).unwrap();
sourcepub fn from_bytes<B: AsRef<[u8]>>(bytes: B, x: i32, y: i32) -> Result<Self>
pub fn from_bytes<B: AsRef<[u8]>>(bytes: B, x: i32, y: i32) -> Result<Self>
Create a new sprite using a slice of bytes, like what is returned from include_bytes!
Don’t forget to call draw()
after this.
let bytes = include_bytes!("../duck.png");
let s = Sprite::from_bytes(bytes, 500, 400).unwrap();
sourcepub fn draw(&mut self, ctx: &mut Context) -> Result<()>
pub fn draw(&mut self, ctx: &mut Context) -> Result<()>
Draws the sprite to the window. This should only be called inside your main event loop.
s.draw(ctx);
sourcepub fn translate<I: Into<Vec2Int>>(&mut self, position: I)
pub fn translate<I: Into<Vec2Int>>(&mut self, position: I)
Translate the sprite, in the form of (delta x, delta y)
s.translate((5, 10));
sourcepub fn set_position<I: Into<Vec2Int>>(&mut self, position: I)
pub fn set_position<I: Into<Vec2Int>>(&mut self, position: I)
Reposition the center of the sprite in the form of (x, y)
s.set_position((5, 10));
sourcepub fn set_angle(&mut self, angle: f64)
pub fn set_angle(&mut self, angle: f64)
Set the angle of the sprite, in degrees of clockwise rotation.
s.set_angle(45.0);
Auto Trait Implementations
impl RefUnwindSafe for Sprite
impl !Send for Sprite
impl !Sync for Sprite
impl Unpin for Sprite
impl UnwindSafe for Sprite
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more