Struct SimpleLinearConfig

Source
pub struct SimpleLinearConfig {
    pub images: Vec<Image>,
    pub timing: Timer,
}
Expand description

The easiest animation system. It renders the images in order, switching to the next one based on the animation speed.

Fields§

§images: Vec<Image>

The images that make up the animation.

§timing: Timer

Controls how fast the animation plays.

Implementations§

Source§

impl SimpleLinearConfig

Source

pub fn into_animation( self, ) -> Linear<Vec<Image>, Box<dyn Fn(&mut Vec<Image>, usize, &mut Graphics, Rectangle) -> Result<()>>, Box<dyn Fn(&Vec<Image>) -> usize>>

Turn the config into an actual animation struct.

Examples found in repository?
examples/01_simple_linear.rs (line 39)
30async fn app(window: Window, mut gfx: Graphics, mut input: Input) -> Result<()> {
31    //load the images that you want to display
32    let i1 = Image::load(&gfx, "img1.png").await?;
33    let i2 = Image::load(&gfx, "img2.png").await?;
34    let i3 = Image::load(&gfx, "img3.png").await?;
35    let i4 = Image::load(&gfx, "img4.png").await?;
36    let images = [i1, i2, i3, i4].into();
37    //set how long every image gets shown
38    let timing = Timer::time_per_second(8.);
39    let mut animation = SimpleLinearConfig { images, timing }.into_animation();
40    let location = Rectangle::new(Vector::new(200., 200.), Vector::new(200., 200.));
41    gfx.clear(Color::WHITE);
42    gfx.present(&window)?;
43
44    loop {
45        while input.next_event().await.is_some() {}
46        gfx.clear(Color::WHITE);
47        animation.draw(&mut gfx, location)?;
48        gfx.present(&window)?;
49    }
50}

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.