pub struct Sprite {Show 14 fields
pub asset_id: AssetId,
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub texture: Option<TextureHandle>,
pub tint: [f32; 4],
pub follow_cursor: bool,
pub visible: bool,
pub screen: Option<AssetId>,
pub fit: SpriteFit,
pub corner_radius: f32,
pub border_width: f32,
pub border_color: [f32; 4],
}Expand description
Screen-space 2D rectangle drawn as a UI overlay each frame.
Sprites are pixel-anchored quads with an RGBA tint. They draw alongside TextLabels, ordered behind labels so text sits on top.
A sprite with a texture draws that image, multiplied by the tint (use a
white tint to show the image unchanged; the tint’s alpha fades it).
Without one, the tint is drawn as a solid-coloured rectangle.
Sprite {
x: 0.0,
y: 0.0,
width: 1280.0,
height: 720.0,
tint: [0.04, 0.06, 0.1, 1.0],
..Default::default()
};Fields§
§asset_id: AssetIdAssigned by the loader; not authored.
x: f32Left edge in screen pixels from the window’s top-left.
y: f32Top edge in screen pixels from the window’s top-left.
width: f32Width in screen pixels.
height: f32Height in screen pixels.
texture: Option<TextureHandle>Texture to draw, sampled over the sprite’s rect and
multiplied by tint. Omitted, the sprite is a solid tint fill.
tint: [f32; 4]RGBA colour the rectangle is filled with, each channel in [0, 1].
follow_cursor: boolWhen true, the sprite acts as an in-engine cursor: it is drawn on top of
the other overlays as an arrow pointer tracking the mouse, with the
pointer at the arrow’s tip. tint is the arrow fill (a contrasting
outline is added automatically) and height its size; width is
ignored so the arrow keeps its shape. The system cursor is hidden while
a visible follow_cursor sprite exists.
visible: boolWhen false the sprite is skipped each frame.
screen: Option<AssetId>Screen this sprite belongs to. Resolved automatically from
the naming convention (<screen>_*); you don’t set this directly.
None means the sprite is always visible (e.g. a scene background).
fit: SpriteFitHow a screen-owned sprite maps from the reference canvas to the window when their aspect ratios differ.
corner_radius: f32Corner rounding radius in the sprite’s own pixel space. 0 keeps
sharp corners; larger values round each corner with a quarter-circle
arc (clamped to half the sprite’s shorter side). The rounded edge is
softly anti-aliased.
border_width: f32Border stroke width in the sprite’s own pixel space, drawn just inside
the sprite’s outline and following its rounded corners. 0 draws no
border; larger values inset the tinted fill by this width and paint the
ring in border_color (clamped to half the sprite’s shorter side).
border_color: [f32; 4]RGBA colour of the border stroke, each channel in [0, 1]. Ignored when
border_width is 0.
Trait Implementations§
Source§impl Component for Sprite
impl Component for Sprite
Source§fn inject_name(&mut self, id: AssetId)
fn inject_name(&mut self, id: AssetId)
Source§fn from_baked(bytes: &[u8]) -> Result<Sprite, CnResult>
fn from_baked(bytes: &[u8]) -> Result<Sprite, CnResult>
Source§fn inject_locator(&mut self, _locator: PayloadLocator)
fn inject_locator(&mut self, _locator: PayloadLocator)
Source§impl ComponentSlot for Sprite
impl ComponentSlot for Sprite
Source§const DISCRIMINANT: u8
const DISCRIMINANT: u8
ComponentId.Source§impl<'de> Deserialize<'de> for Sprite
impl<'de> Deserialize<'de> for Sprite
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Sprite, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Sprite, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl From<Sprite> for ComponentAsset
impl From<Sprite> for ComponentAsset
Source§fn from(c: Sprite) -> ComponentAsset
fn from(c: Sprite) -> ComponentAsset
impl RuntimeComponent for Sprite
Source§impl Serialize for Sprite
impl Serialize for Sprite
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for Sprite
impl RefUnwindSafe for Sprite
impl Send for Sprite
impl Sync for Sprite
impl Unpin for Sprite
impl UnsafeUnpin for Sprite
impl UnwindSafe 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> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().