#animation #graphics #quicksilver #gamedev #game

silver_animation

A basic animation system for quicksilver

5 releases

0.1.0 Nov 28, 2020
0.1.0-alpha0.4 Aug 10, 2020
0.1.0-alpha0.3 Jun 10, 2020
0.1.0-alpha0.2 Jun 7, 2020
0.1.0-alpha0.1 May 20, 2020

#1838 in Game dev

MIT/Apache

25KB
303 lines

silver_animation

silver_animation is a simple and basic animation system for quicksilver. It allows you to either use a list of images or take full control and render something however you want.

It also provides a set of traits that provide a base on how to interact with animations. These can be used as building blocks for your own animation system(s)

Maintenance

Since quicksilver is no longer actively developped , I no longer use it. As a result, I also stopped using silver_animation. I will still respond to pull requests and the like, but don't expect any new features from me.

example

use quicksilver::{
    geom::{Rectangle, Shape, Transform, Vector},
    graphics::{Color, Graphics, Image},
    run, Input, Result, Settings, Timer, Window,
};
use silver_animation::SimpleLinearConfig;
use silver_animation::LinearConfig;

fn main() {
    run(
        Settings {
            size: Vector::new(800.0, 600.0).into(),
            title: "Simple Linear Example",
            ..Settings::default()
        },
        app,
    );
}

async fn app(window: Window, mut gfx: Graphics, mut inputs: Input) -> Result<()> {
    let images = vec![
        Image::load(&gfx, "img1.png").await?,
        Image::load(&gfx, "img2.png").await?,
        Image::load(&gfx, "img3.png").await?,
        Image::load(&gfx, "img4.png").await?,
    ];
    let timing = Timer::time_per_second(8.);
    let mut simple_animation = SimpleLinearConfig { images, timing }.to_animation();

    let image = Image::load(&gfx, "img1.png").await?;
    let timing = Timer::time_per_second(30.);

    let step_size: f32 = 5.;
    let amount_of_steps = (255. / step_size).ceil() as usize;
    let mut custom_animation = LinearConfig {
        begin_state: image,
        timing,
        draw: |state, tick, gfx, location| {
            gfx.draw_image_tinted(
                state,
                location,
                Color::from_rgba(0, (step_size * tick as f32) as u8, 0, 1.0),
            );
            Ok(())
        },
        max_frames: |_| amount_of_steps,
    }
    .to_animation();

    let simple_animation_location = Rectangle::new((100, 100), (100, 100));
    let custom_animation_location = Rectangle::new((100, 150), (100, 100));
    gfx.clear(Color::WHITE);
    gfx.present(&window)?;

    loop {
        while let Some(_) = inputs.next_event().await {}
        gfx.clear(Color::WHITE);
        simple_animation.draw(&mut gfx, simple_animation_location)?;
        custom_animation.draw(&mut gfx, custom_animation_location)?;
        gfx.present(&window)?;
    }
}

Dependencies

~8–18MB
~256K SLoC