-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathdraw_animation_list.rs
59 lines (51 loc) · 1.7 KB
/
draw_animation_list.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use notan::draw::*;
use notan::prelude::*;
#[derive(AppState)]
struct State {
textures: Vec<Texture>,
time: f32,
}
impl State {
fn new(gfx: &mut Graphics) -> Self {
let texture_data = vec![
include_bytes!("assets/pixelExplosion00.png").to_vec(),
include_bytes!("assets/pixelExplosion01.png").to_vec(),
include_bytes!("assets/pixelExplosion02.png").to_vec(),
include_bytes!("assets/pixelExplosion03.png").to_vec(),
include_bytes!("assets/pixelExplosion04.png").to_vec(),
include_bytes!("assets/pixelExplosion05.png").to_vec(),
include_bytes!("assets/pixelExplosion06.png").to_vec(),
include_bytes!("assets/pixelExplosion07.png").to_vec(),
include_bytes!("assets/pixelExplosion08.png").to_vec(),
];
let textures = texture_data
.iter()
.map(|d| gfx.create_texture().from_image(d).build().unwrap())
.collect();
Self {
textures,
time: 0.0,
}
}
}
#[notan_main]
fn main() -> Result<(), String> {
notan::init_with(State::new)
.add_config(DrawConfig)
.draw(draw)
.build()
}
fn draw(app: &mut App, gfx: &mut Graphics, state: &mut State) {
let mut draw = gfx.create_draw();
draw.clear(Color::BLACK);
// An animation list take a &[&Texture] as frames
draw.animation_list(&state.textures.iter().collect::<Vec<_>>())
// just a matrix scale
.scale(2.0, 2.0)
// just a matrix translation
.translate(300.0, 200.0)
// normalized frame time
.time(state.time);
gfx.render(&draw);
state.time += app.timer.delta_f32() * 2.0;
}