pub struct Animator { /* private fields */ }Expand description
Plays a Clip on its entity’s Sprite.
The system nadir::animate, first in the frame stage Animate,
advances it by how long the simulation ran since the last frame (the
change in RenderFrame::time), so clips slow and stop with the clock,
as animated tiles do. It then writes the texture and the uv of the frame
it shows into the Sprite, and its size and pivot if the frame has a
Placement, which nadir::extract_sprites draws.
Its time is frame state. It moves once a frame, by however the ticks
fell into frames, so a fixed system may call Animator::play and
Animator::restart, but must not decide anything by
Animator::elapsed, Animator::is_finished or what it writes into
the Sprite: to wait for a clip, count ticks (roadmap M4.7).
An animator that starts (new, played or restarted) is advanced on its first frame by that frame’s whole step, so it is first drawn up to one frame into its clip: after a hitch (frames are at most 250 ms), early frames can be skipped, and a clip that plays once and is no longer than the step ends on its first frame.
A clip replaced under its handle, as the hot reload replaces an
atlas’s under dev, plays on from the animator’s time: a looping one
wraps it by its new duration, and one that plays once and finished
holds its new last frame, with no second AnimationFinished.
It is reflected by hand as its clip’s name in the Clips, and a read
one starts its clip: its time and finished flag are left out (ADR-0024,
ADR-0038).
Implementations§
Source§impl Animator
impl Animator
Sourcepub const fn starting_at(clip: Handle<Clip>, elapsed: Duration) -> Self
pub const fn starting_at(clip: Handle<Clip>, elapsed: Duration) -> Self
Plays clip as if it had started elapsed ago: a looping clip from
elapsed past its last start, and a clip that plays once at most
from its end, which it then reaches on its first frame.
Started at RenderFrame::time, from a system in a tick or in a frame,
or before the first frame, a looping clip keeps in step with the
animated tiles of the same frame lengths, to within the millisecond
that the tiles’ time is rounded to.
Sourcepub fn elapsed(&self) -> Duration
pub fn elapsed(&self) -> Duration
How far into its clip it is: as of the last frame, or as set since
by Animator::starting_at, Animator::play or
Animator::restart, which a looping clip wraps at its next frame.
Frame state (see Animator).
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Whether its clip plays once and reached its end by the last frame:
frame state (see Animator).
Sourcepub fn play(&mut self, clip: Handle<Clip>)
pub fn play(&mut self, clip: Handle<Clip>)
Plays clip from its start, unless it is the clip playing already,
which goes on: a system may call this every tick. A clip that played
once and finished stays finished: Animator::restart plays it
again.
Trait Implementations§
impl Component for Animator
impl Copy for Animator
impl Eq for Animator
Source§impl FromValue for Animator
impl FromValue for Animator
Source§const TYPE_NAME: &'static str = "Animator"
const TYPE_NAME: &'static str = "Animator"
Reflect::type_name gives it.Source§fn from_value(
value: &Value,
cx: &mut ReflectContext<'_>,
) -> Result<Self, ReflectError>
fn from_value( value: &Value, cx: &mut ReflectContext<'_>, ) -> Result<Self, ReflectError>
value. Read moreSource§impl Reflect for Animator
impl Reflect for Animator
Source§fn to_value(&self, cx: &mut ReflectContext<'_>) -> Value
fn to_value(&self, cx: &mut ReflectContext<'_>) -> Value
Its clip’s name. A clip that has none, or a context with no
Clips, is written as null, with a warning; for a hash, as its
handle’s index and generation, which tell clips apart and are the
same on every run, with no warning.
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>
Plays the clip the value names, from its start.
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.