pub struct Sprite {}Fields§
§texture: Arc<Texture>§x: f32§y: f32§z: f32§width: f32§height: f32§src_x: f32§src_y: f32§src_w: f32§src_h: f32§tint: Color§highlight: ColorRGBA overlay blended over the shaded sprite (mix(shaded, highlight.rgb, highlight.a)),
applied on top of tint’s multiplicative recolor rather than replacing it. Alpha 0 (the
default) means no highlight. Intended for editor-style hover/selection feedback; only
consumed by Sprite::draw_world — screen-space Sprite::draw ignores it.
transform: Mat4Model matrix applied to the quad in the sprite’s local space, where the origin is the
quad’s anchor corner and the quad spans (0, 0)..(width, height). The transformed quad
is then positioned at (x, y, z), so translation here is relative to that position.
Defaults to glam::Mat4::IDENTITY. Prefer building it up through the
Transformable methods, which rotate and scale around the sprite’s center.
Implementations§
Source§impl Sprite
impl Sprite
pub fn new(texture: Arc<Texture>) -> Self
Sourcepub fn draw(&self, pass: &mut DrawPass<'_>)
pub fn draw(&self, pass: &mut DrawPass<'_>)
Draws the sprite in screen space (pixel coordinates), ignoring the camera. Use for UI/HUD elements.
Sourcepub fn fit_within_unit_square(&mut self)
pub fn fit_within_unit_square(&mut self)
Rescales width/height (preserving aspect ratio) so the sprite fits within a 1×1 unit
square in world space, without ever upscaling past its current size. Sprite::new sizes
the quad to the texture’s native pixel dimensions, which is normally far too large as a
world-unit size — call this right after construction when the caller has no better size
of its own to apply (e.g. attaching a sprite with no explicit width/height).
Sourcepub fn draw_world(&self, pass: &mut DrawPass<'_>)
pub fn draw_world(&self, pass: &mut DrawPass<'_>)
Draws the sprite as a quad in world space, transformed by the camera.
Trait Implementations§
Source§impl Transformable for Sprite
Rotations and scales pivot around the middle of the sprite’s quad, so a sprite spins in
place rather than swinging around its anchor corner.
impl Transformable for Sprite
Rotations and scales pivot around the middle of the sprite’s quad, so a sprite spins in place rather than swinging around its anchor corner.
sprite.reset_transform().rotate(angle).scale_uniform(2.0);Source§fn transform_mut(&mut self) -> &mut Mat4
fn transform_mut(&mut self) -> &mut Mat4
Source§fn pivot(&self) -> Vec3
fn pivot(&self) -> Vec3
Source§fn set_transform(&mut self, transform: Mat4) -> &mut Selfwhere
Self: Sized,
fn set_transform(&mut self, transform: Mat4) -> &mut Selfwhere
Self: Sized,
Source§fn reset_transform(&mut self) -> &mut Selfwhere
Self: Sized,
fn reset_transform(&mut self) -> &mut Selfwhere
Self: Sized,
Source§fn apply(&mut self, transform: Mat4) -> &mut Selfwhere
Self: Sized,
fn apply(&mut self, transform: Mat4) -> &mut Selfwhere
Self: Sized,
transform onto the current matrix, about the local origin.Source§fn apply_about_pivot(&mut self, transform: Mat4) -> &mut Selfwhere
Self: Sized,
fn apply_about_pivot(&mut self, transform: Mat4) -> &mut Selfwhere
Self: Sized,
transform onto the current matrix, about Transformable::pivot.Source§fn translate(&mut self, x: f32, y: f32) -> &mut Selfwhere
Self: Sized,
fn translate(&mut self, x: f32, y: f32) -> &mut Selfwhere
Self: Sized,
Source§fn translate3(&mut self, offset: Vec3) -> &mut Selfwhere
Self: Sized,
fn translate3(&mut self, offset: Vec3) -> &mut Selfwhere
Self: Sized,
offset in local space.Source§fn rotate(&mut self, radians: f32) -> &mut Selfwhere
Self: Sized,
fn rotate(&mut self, radians: f32) -> &mut Selfwhere
Self: Sized,
Source§fn rotate_degrees(&mut self, degrees: f32) -> &mut Selfwhere
Self: Sized,
fn rotate_degrees(&mut self, degrees: f32) -> &mut Selfwhere
Self: Sized,
Transformable::rotate, taking degrees.Source§fn rotate_x(&mut self, radians: f32) -> &mut Selfwhere
Self: Sized,
fn rotate_x(&mut self, radians: f32) -> &mut Selfwhere
Self: Sized,
Source§fn rotate_y(&mut self, radians: f32) -> &mut Selfwhere
Self: Sized,
fn rotate_y(&mut self, radians: f32) -> &mut Selfwhere
Self: Sized,
Source§fn rotate_z(&mut self, radians: f32) -> &mut Selfwhere
Self: Sized,
fn rotate_z(&mut self, radians: f32) -> &mut Selfwhere
Self: Sized,
Source§fn rotate_quat(&mut self, rotation: Quat) -> &mut Selfwhere
Self: Sized,
fn rotate_quat(&mut self, rotation: Quat) -> &mut Selfwhere
Self: Sized,
Source§fn scale(&mut self, x: f32, y: f32) -> &mut Selfwhere
Self: Sized,
fn scale(&mut self, x: f32, y: f32) -> &mut Selfwhere
Self: Sized,
Source§fn scale_uniform(&mut self, factor: f32) -> &mut Selfwhere
Self: Sized,
fn scale_uniform(&mut self, factor: f32) -> &mut Selfwhere
Self: Sized,
Auto Trait Implementations§
impl !RefUnwindSafe for Sprite
impl !UnwindSafe for Sprite
impl Freeze for Sprite
impl Send for Sprite
impl Sync for Sprite
impl Unpin for Sprite
impl UnsafeUnpin for Sprite
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> Variant for T
impl<T> Variant for T
§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Variant] trait object to &mut dyn Any.§fn as_boxed_any(self: Box<T>) -> Box<dyn Any>
fn as_boxed_any(self: Box<T>) -> Box<dyn Any>
Variant] trait object to Box<dyn Any>.§fn clone_object(&self) -> Box<dyn Variant>
fn clone_object(&self) -> Box<dyn Variant>
Variant] trait object.