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
impl SimpleLinearConfig
Sourcepub fn into_animation(
self,
) -> Linear<Vec<Image>, Box<dyn Fn(&mut Vec<Image>, usize, &mut Graphics, Rectangle) -> Result<()>>, Box<dyn Fn(&Vec<Image>) -> usize>>
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§
impl Freeze for SimpleLinearConfig
impl !RefUnwindSafe for SimpleLinearConfig
impl !Send for SimpleLinearConfig
impl !Sync for SimpleLinearConfig
impl Unpin for SimpleLinearConfig
impl !UnwindSafe for SimpleLinearConfig
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