Skip to main content

Sprite

Struct Sprite 

Source
pub struct Sprite {
    pub texture: Handle<Texture>,
    pub uv: Rect,
    pub size: Vec2,
    pub pivot: Vec2,
    pub rotation: f32,
    pub color: Color,
    pub layer: u8,
    pub sort: SortMode,
    pub flip: Flip,
}
Expand description

What an entity looks like: a sprite drawn at its Transform, between ticks part of the way from its PrevTransform.

It holds what SpriteDraw holds but the position. It is reflected by hand, its texture as its page’s path, and prefabs may name a frame of a cooked atlas instead (crate::reflected, ADR-0038); a hash leaves out what nadir::animate writes, below.

On an entity with an Animator, the system nadir::animate writes its texture and uv each frame, and its size and pivot when the frame shown has a Placement, as a cooked atlas’s clips’ frames do; on one with a Facing, its flip.x.

Fields§

§texture: Handle<Texture>

The texture, usually an atlas page.

§uv: Rect

The region of the texture, normalized: (0, 0) to (1, 1) is all of it.

§size: Vec2

The size in world units.

§pivot: Vec2

The point of the sprite at the entity’s position, normalized: (0.5, 1) is the middle of its bottom edge, its feet.

§rotation: f32

Radians, clockwise on screen, about the pivot.

§color: Color

A tint, sRGB, multiplied with the texture in linear light.

§layer: u8

Higher layers are drawn in front of lower ones.

§sort: SortMode

How it is ordered within its layer.

§flip: Flip

Which way it is mirrored, about its pivot (render’s SpriteDraw::flip).

Implementations§

Source§

impl Sprite

Source

pub fn new(texture: Handle<Texture>, size: Vec2) -> Self

A sprite of all of texture, size large, with its feet at the entity’s position: untinted, unrotated, y-sorted in layer 0, as SpriteDraw::new makes one.

Source

pub fn from_atlas( texture: Handle<Texture>, sprite: &AtlasSprite, frame: usize, ) -> Option<Self>

A sprite of frame frame of sprite, from a cooked Atlas, in texture, which must be the frame’s page, with the sprite’s pivot at the entity’s position: the frame’s trimmed size, one world unit a pixel, placed so that its pixels are where the untrimmed cell would have them, up to the rounding of its normalized pivot; otherwise as Sprite::new makes one. None if sprite has no such frame, or is a tile set.

Flipped, it mirrors about its pivot, so the trimmed quad lands where the mirrored cell’s pixels would. Animated, by a clip of Clips::add_atlas, each frame is placed by its own trimmed size and pivot (ClipFrame::from_atlas).

Source

pub fn draw(&self, position: Vec2) -> SpriteDraw

The sprite to draw with its pivot at position.

Trait Implementations§

Source§

impl Clone for Sprite

Source§

fn clone(&self) -> Self

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§

impl Copy for Sprite

Source§

impl Debug for Sprite

Source§

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

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

impl FromValue for Sprite

Source§

fn from_value( value: &Value, cx: &mut ReflectContext<'_>, ) -> Result<Self, ReflectError>

A sprite of its atlas form, or of its texture, with all of it as its region and no size until the value gives one; then the other fields the value names.

Source§

const TYPE_NAME: &'static str = "Sprite"

The type’s name, as Reflect::type_name gives it.
Source§

impl PartialEq for Sprite

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Reflect for Sprite

Source§

fn apply_value( &mut self, value: &Value, cx: &mut ReflectContext<'_>, ) -> Result<(), ReflectError>

Sets the fields the value names; an atlas form sets the texture, uv, size and pivot, and the fields beside it apply over it.

Source§

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

The type’s name: for the macros’ types, its name as written (Health), which prefabs and saves use.
Source§

fn kind(&self) -> ReflectKind

What sort of value it is.
Source§

fn fields(&self) -> &'static [FieldInfo]

The fields of a struct, in order; none for other kinds.
Source§

fn field(&self, _index: usize) -> Option<&dyn Reflect>

Field index of a struct, or element index of a list or an option.
Source§

fn field_mut(&mut self, _index: usize) -> Option<&mut dyn Reflect>

Field or element index, to change it.
Source§

fn to_value(&self, cx: &mut ReflectContext<'_>) -> Value

The value as a Value.
Source§

fn variants(&self) -> &'static [&'static str]

The variants of an enum, by name, in order, as data writes them: what an inspector offers to pick from. None for other kinds, and by default: reflect_enum! gives its enum’s.
Source§

impl StructuralPartialEq for Sprite

Auto Trait Implementations§

§

impl Forget for Sprite

§

impl Freeze for Sprite

§

impl Move 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> 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> 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.