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 paint a ring of that width in border_color
(clamped to half the sprite’s shorter side). An opaque fill is inset
under the ring; a translucent fill keeps the whole rect, so the ring
sits over its edge and whatever is behind still shows through.
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<Self, CnResult>
fn from_baked(bytes: &[u8]) -> Result<Self, 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.