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: RectThe region of the texture, normalized: (0, 0) to (1, 1) is all of it.
size: Vec2The size in world units.
pivot: Vec2The point of the sprite at the entity’s position, normalized: (0.5, 1) is the middle of its bottom edge, its feet.
rotation: f32Radians, clockwise on screen, about the pivot.
color: ColorA tint, sRGB, multiplied with the texture in linear light.
layer: u8Higher layers are drawn in front of lower ones.
sort: SortModeHow it is ordered within its layer.
flip: FlipWhich way it is mirrored, about its pivot (render’s
SpriteDraw::flip).
Implementations§
Source§impl Sprite
impl Sprite
Sourcepub fn new(texture: Handle<Texture>, size: Vec2) -> Self
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.
Sourcepub fn from_atlas(
texture: Handle<Texture>,
sprite: &AtlasSprite,
frame: usize,
) -> Option<Self>
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).
Sourcepub fn draw(&self, position: Vec2) -> SpriteDraw
pub fn draw(&self, position: Vec2) -> SpriteDraw
The sprite to draw with its pivot at position.
Trait Implementations§
impl Component for Sprite
impl Copy for Sprite
Source§impl FromValue for Sprite
impl FromValue for Sprite
Source§fn from_value(
value: &Value,
cx: &mut ReflectContext<'_>,
) -> Result<Self, ReflectError>
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"
const TYPE_NAME: &'static str = "Sprite"
Reflect::type_name gives it.Source§impl Reflect for Sprite
impl Reflect for Sprite
Source§fn apply_value(
&mut self,
value: &Value,
cx: &mut ReflectContext<'_>,
) -> Result<(), ReflectError>
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
fn type_name(&self) -> &'static str
Health), which prefabs and saves use.Source§fn kind(&self) -> ReflectKind
fn kind(&self) -> ReflectKind
Source§fn fields(&self) -> &'static [FieldInfo]
fn fields(&self) -> &'static [FieldInfo]
Source§fn field(&self, _index: usize) -> Option<&dyn Reflect>
fn field(&self, _index: usize) -> Option<&dyn Reflect>
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>
fn field_mut(&mut self, _index: usize) -> Option<&mut dyn Reflect>
index, to change it.Source§fn variants(&self) -> &'static [&'static str]
fn variants(&self) -> &'static [&'static str]
reflect_enum! gives its enum’s.