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

Representation of a sprite.

Fields

rect: Rect

Implementations

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

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

Draws the sprite to the window. This should only be called inside your main event loop.

s.draw(ctx);

Translate the sprite, in the form of (delta x, delta y)

s.translate((5, 10));

Reposition the center of the sprite in the form of (x, y)

s.set_position((5, 10));

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

s.set_angle(45.0);

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

let angle = s.angle();

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.