Struct Sprite

Source
pub struct Sprite<'a, 'b> { /* private fields */ }
Expand description

Sprite builder struct. Call finish to draw the sprite.

Created by Spritesheet::draw, and usually used as a temporary value, as this is a builder struct. See the Spritesheet::draw documentation for examples.

Implementations§

Source§

impl<'a, 'b> Sprite<'a, 'b>

Source

pub fn finish(&mut self)

Renders the quad specified by this struct.

Source

pub fn z(&mut self, z: f32) -> &mut Self

Specifies the Z-coordinate of the sprite. Sprites with a higher Z-coordinate will be rendered over ones with a lower Z-coordinate.

§Alpha blending and Z-coordinates

When drawing sprites on top of each other, with alpha_blending set to true, draw the ones with the highest Z-coordinate the last, and avoid overlapping the minimum and maximum Z-coordinate ranges between draw calls.

Explanation: Draw call rendering order is decided by the highest z-coordinate that each call has to draw. To get proper blending, the sprites furthest back need to be rendered first. Therefore, if a draw call is ordered to be rendered the last, but has sprites behind some other sprites, they will not get blended as hoped. However, this ordering only applies between draw calls that have alpha_blending set to true: non-blended draw calls are always drawn before blended ones.

Source

pub fn coordinates<R: Into<Rect>>(&mut self, rect: R) -> &mut Self

Specifies the screen coordinates (in logical pixels) where the quad is drawn.

Source

pub fn physical_coordinates<R: Into<Rect>>(&mut self, rect: R) -> &mut Self

Specifies the screen coordinates (in physical pixels) where the quad is drawn.

Source

pub fn texture_coordinates<R: Into<Rect>>(&mut self, rect: R) -> &mut Self

Specifies the texture coordinates (in actual pixels, in the texture’s coordinate space) from where the quad is sampled.

Source

pub fn pixel_alignment(&mut self) -> &mut Self

Rounds previously set coordinates (coordinates) so that they align with the physical pixels of the monitor.

This might help you with weird visual glitches, especially if you’re trying to render quads that have the same physical pixel size as the texture it’s sampling.

Source

pub fn uvs<R: Into<Rect>>(&mut self, rect: R) -> &mut Self

Specifies the texture coordinates (as UVs, ie. 0.0 - 1.0) from where the quad is sampled.

Source

pub fn clip_area<R: Into<Rect>>(&mut self, rect: R) -> &mut Self

Specifies the clip area. Only the parts that overlap between the clip area and the area specified by coordinates are rendered.

Source

pub fn color( &mut self, (red, green, blue, alpha): (f32, f32, f32, f32), ) -> &mut Self

Specifies the color tint of the quad.

Source

pub fn rotation( &mut self, rotation: f32, pivot_x: f32, pivot_y: f32, ) -> &mut Self

Specifies the rotation (in radians) and pivot of the quad, relative to the sprite’s origin.

Auto Trait Implementations§

§

impl<'a, 'b> Freeze for Sprite<'a, 'b>

§

impl<'a, 'b> RefUnwindSafe for Sprite<'a, 'b>

§

impl<'a, 'b> Send for Sprite<'a, 'b>

§

impl<'a, 'b> Sync for Sprite<'a, 'b>

§

impl<'a, 'b> Unpin for Sprite<'a, 'b>

§

impl<'a, 'b> !UnwindSafe for Sprite<'a, 'b>

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.