Skip to main content

Sprite

Struct Sprite 

Source
pub struct Sprite {
Show 13 fields pub texture: Arc<Texture>, pub x: f32, pub y: f32, pub z: f32, pub width: f32, pub height: f32, pub src_x: f32, pub src_y: f32, pub src_w: f32, pub src_h: f32, pub tint: Color, pub highlight: Color, pub transform: Mat4,
}

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: Color

RGBA 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: Mat4

Model 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

Source

pub fn new(texture: Arc<Texture>) -> Self

Source

pub fn draw(&self, pass: &mut DrawPass<'_>)

Draws the sprite in screen space (pixel coordinates), ignoring the camera. Use for UI/HUD elements.

Source

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).

Source

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 Clone for Sprite

Source§

fn clone(&self) -> Sprite

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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.

sprite.reset_transform().rotate(angle).scale_uniform(2.0);
Source§

fn transform(&self) -> Mat4

The current model matrix.
Source§

fn transform_mut(&mut self) -> &mut Mat4

Mutable access to the model matrix.
Source§

fn pivot(&self) -> Vec3

Local-space point that rotations and scales turn around. Defaults to the local origin.
Source§

fn set_transform(&mut self, transform: Mat4) -> &mut Self
where Self: Sized,

Replaces the model matrix outright, discarding any accumulated transforms.
Source§

fn reset_transform(&mut self) -> &mut Self
where Self: Sized,

Clears the model matrix back to the identity.
Source§

fn apply(&mut self, transform: Mat4) -> &mut Self
where Self: Sized,

Composes transform onto the current matrix, about the local origin.
Source§

fn apply_about_pivot(&mut self, transform: Mat4) -> &mut Self
where Self: Sized,

Composes transform onto the current matrix, about Transformable::pivot.
Source§

fn translate(&mut self, x: f32, y: f32) -> &mut Self
where Self: Sized,

Moves along the local X and Y axes.
Source§

fn translate3(&mut self, offset: Vec3) -> &mut Self
where Self: Sized,

Moves by offset in local space.
Source§

fn rotate(&mut self, radians: f32) -> &mut Self
where Self: Sized,

Rotates around the Z axis — the in-plane spin for 2D content.
Source§

fn rotate_degrees(&mut self, degrees: f32) -> &mut Self
where Self: Sized,

Transformable::rotate, taking degrees.
Source§

fn rotate_x(&mut self, radians: f32) -> &mut Self
where Self: Sized,

Rotates around the X axis.
Source§

fn rotate_y(&mut self, radians: f32) -> &mut Self
where Self: Sized,

Rotates around the Y axis.
Source§

fn rotate_z(&mut self, radians: f32) -> &mut Self
where Self: Sized,

Rotates around the Z axis.
Source§

fn rotate_quat(&mut self, rotation: Quat) -> &mut Self
where Self: Sized,

Applies an arbitrary rotation.
Source§

fn scale(&mut self, x: f32, y: f32) -> &mut Self
where Self: Sized,

Scales the X and Y axes independently.
Source§

fn scale_uniform(&mut self, factor: f32) -> &mut Self
where Self: Sized,

Scales every axis by the same factor.
Source§

fn scale3(&mut self, scale: Vec3) -> &mut Self
where Self: Sized,

Scales by scale in local space.
Source§

fn flip_x(&mut self) -> &mut Self
where Self: Sized,

Mirrors across the pivot’s vertical axis.
Source§

fn flip_y(&mut self) -> &mut Self
where Self: Sized,

Mirrors across the pivot’s horizontal axis.

Auto Trait Implementations§

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> Variant for T
where T: Any + Clone + SendSync,

§

fn as_any(&self) -> &(dyn Any + 'static)

Convert this [Variant] trait object to &dyn Any.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert this [Variant] trait object to &mut dyn Any.
§

fn as_boxed_any(self: Box<T>) -> Box<dyn Any>

Convert this [Variant] trait object to Box<dyn Any>.
§

fn type_name(&self) -> &'static str

Get the name of this type.
§

fn clone_object(&self) -> Box<dyn Variant>

Clone this [Variant] trait object.
§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more