Skip to main content

Sprite

Struct Sprite 

Source
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: AssetId

Assigned by the loader; not authored.

§x: f32

Left edge in screen pixels from the window’s top-left.

§y: f32

Top edge in screen pixels from the window’s top-left.

§width: f32

Width in screen pixels.

§height: f32

Height 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: bool

When 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: bool

When 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: SpriteFit

How a screen-owned sprite maps from the reference canvas to the window when their aspect ratios differ.

§corner_radius: f32

Corner 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: f32

Border 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 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 Component for Sprite

Source§

const NAME: &'static str = "Sprite"

The registry name a world authors this component under.
Source§

fn inject_name(&mut self, id: AssetId)

Called after construction to inject the asset’s identity from the blob def. Only meaningful for components that look themselves up by id at runtime. The default implementation does nothing.
Source§

fn from_baked(bytes: &[u8]) -> Result<Self, CnResult>

Reconstruct this component from a blob record, whose bytes are the serialized runtime component (cook already ran the asset -> component translation). The default rejects: runtime-only components are never stored in a blob, so only loadable types provide an implementation.
Source§

fn inject_locator(&mut self, _locator: PayloadLocator)

Called after construction to inject the payload locator from the blob def. Only meaningful for components with a compiled payload. The default implementation does nothing (correct for most components).
Source§

impl ComponentSlot for Sprite

Source§

const DISCRIMINANT: u8

The component type’s stable id, used as its ComponentId.
Source§

fn slot(s: &ComponentStorage) -> &Column<Self>

Borrow this type’s column out of the storage.
Source§

fn slot_mut(s: &mut ComponentStorage) -> &mut Column<Self>

Mutably borrow this type’s column out of the storage.
Source§

impl Debug for Sprite

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Sprite

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Sprite
where Sprite: Default,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Sprite> for ComponentAsset

Source§

fn from(c: Sprite) -> Self

Converts to this type from the input type.
Source§

impl RuntimeComponent for Sprite

Source§

impl Serialize for Sprite

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.