Skip to main content

Animator

Struct Animator 

Source
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

Source

pub const fn new(clip: Handle<Clip>) -> Self

Plays clip from its start.

Source

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.

Source

pub fn clip(&self) -> Handle<Clip>

The clip it plays.

Source

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).

Source

pub fn is_finished(&self) -> bool

Whether its clip plays once and reached its end by the last frame: frame state (see Animator).

Source

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.

Source

pub fn restart(&mut self)

Plays its clip from the start again.

Trait Implementations§

Source§

impl Clone for Animator

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 Animator

Source§

impl Copy for Animator

Source§

impl Debug for Animator

Source§

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

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

impl Eq for Animator

Source§

impl FromValue for Animator

Source§

const TYPE_NAME: &'static str = "Animator"

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

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

Makes a value of the type from value. Read more
Source§

impl PartialEq for Animator

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 Animator

Source§

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>

Plays the clip the value names, from its start.

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 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 Animator

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