Sprite

Struct Sprite 

Source
pub struct Sprite {
    pub rect: Rect,
    /* private fields */
}
Expand description

Representation of a sprite.

Fields§

§rect: Rect

Implementations§

Source§

impl Sprite

Source

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();
Source

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();
Source

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);
Source

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));
Source

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));
Source

pub fn set_angle(&mut self, angle: f64)

Set the angle of the sprite, in degrees of clockwise rotation.

s.set_angle(45.0);
Source

pub fn angle(&self) -> f64

Get the angle of the sprite, in degrees of clockwise rotation.

let angle = s.angle();
Source

pub fn position(&self) -> Vec2Int

Get the x and y coordinates of the center of the sprite, in the form of (x, y).

let (x, y) = s.position().into();

Auto Trait Implementations§

§

impl Freeze for Sprite

§

impl RefUnwindSafe for Sprite

§

impl !Send for Sprite

§

impl !Sync for Sprite

§

impl Unpin for Sprite

§

impl UnwindSafe for Sprite

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.