#[repr(C)]pub struct Animation {
pub sheet: SpriteSheet,
pub first: u32,
pub frames: u32,
pub fps: f32,
pub looping: bool,
pub time: f32,
}Expand description
Plays frames of a SpriteSheet on an entity’s Sprite. The built-in
animate_sprites system advances it every frame.
ctx.world.spawn((
Transform2D::at(vec2(200.0, 200.0)),
sheet.sprite(0),
Animation::new(sheet, 0..8, 12.0), // frames 0-7 at 12 frames per second, looping
));Fields§
§sheet: SpriteSheetThe frames come from this sheet.
first: u32First frame and how many frames to play.
frames: u32How many frames to play, from first.
fps: f32Frames per second.
looping: boolStart over at the end (default), or stop on the last frame.
time: f32Seconds played so far.
Implementations§
Source§impl Animation
impl Animation
Sourcepub fn new(sheet: SpriteSheet, frames: Range<u32>, fps: f32) -> Self
pub fn new(sheet: SpriteSheet, frames: Range<u32>, fps: f32) -> Self
Plays frames of sheet at fps, looping.
Examples found in repository?
examples/tiles.rs (line 103)
88fn setup(ctx: &mut Ctx, side: u32) {
89 let tiles = tileset(ctx);
90 let mut map = TileMap::new(tiles, side, side);
91 for y in 0..side {
92 for x in 0..side {
93 map.set(x, y, Some(terrain(x as f32, y as f32)));
94 }
95 }
96 ctx.world.spawn((Transform2D::default(), map));
97
98 let blob = creature(ctx);
99 let mut rng = Rng::new(7);
100 let world = (side * TILE) as f32;
101 ctx.world.spawn_batch((0..20_000).map(|_| {
102 let at = vec2(rng.range(0.0, world), rng.range(0.0, world));
103 let mut walk = Animation::new(blob, 0..8, rng.range(6.0, 12.0));
104 walk.time = rng.f32(); // out of step with each other
105 (
106 Transform2D::at(at),
107 blob.sprite(0),
108 walk,
109 Wander(rng.unit_vec2() * 20.0),
110 )
111 }));
112 ctx.camera.zoom = 2.0;
113 ctx.camera.look_at(vec2(world, world) / 2.0);
114}Sourcepub fn once(self) -> Self
pub fn once(self) -> Self
Same animation, played once and then held on its last frame.
let explode = Animation::new(sheet, 8..16, 24.0).once();Sourcepub fn current_frame(&self) -> u32
pub fn current_frame(&self) -> u32
The frame showing now (an index into the sheet).
let walk = Animation::new(sheet, 4..8, 10.0);
assert_eq!(walk.current_frame(), 4);Trait Implementations§
impl StructuralPartialEq for Animation
Auto Trait Implementations§
impl Forget for Animation
impl Freeze for Animation
impl RefUnwindSafe for Animation
impl Send for Animation
impl Sync for Animation
impl Unpin for Animation
impl UnsafeUnpin for Animation
impl UnwindSafe for Animation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Component for T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
impl<T> MaybeSync for T
impl<T> MaybeSync for T
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
impl<T> SerializableAny for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.