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>
impl<'a, 'b> Sprite<'a, 'b>
Sourcepub fn z(&mut self, z: f32) -> &mut Self
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.
Sourcepub fn coordinates<R: Into<Rect>>(&mut self, rect: R) -> &mut Self
pub fn coordinates<R: Into<Rect>>(&mut self, rect: R) -> &mut Self
Specifies the screen coordinates (in logical pixels) where the quad is drawn.
Sourcepub fn physical_coordinates<R: Into<Rect>>(&mut self, rect: R) -> &mut Self
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.
Sourcepub fn texture_coordinates<R: Into<Rect>>(&mut self, rect: R) -> &mut Self
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.
Sourcepub fn pixel_alignment(&mut self) -> &mut Self
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.
Sourcepub fn uvs<R: Into<Rect>>(&mut self, rect: R) -> &mut Self
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.
Sourcepub fn clip_area<R: Into<Rect>>(&mut self, rect: R) -> &mut Self
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.