-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathanimation.rs
61 lines (48 loc) · 1.5 KB
/
animation.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
60
61
use peacock::graphics::{self, Animation, DrawAnimationParams, Image, Rectangle, View};
use peacock::window;
use peacock::{ContextBuilder, Result, State};
type Context = peacock::Context<()>;
struct AnimationExample {
animation: Animation,
}
impl AnimationExample {
fn new(ctx: &mut Context) -> Result<Self> {
let sprite_sheet = Image::from_file(ctx, "examples/res/0x72_dungeon_ii.png")?;
let animation = Animation::new(
sprite_sheet,
vec![
Rectangle::<i32>::new(128, 76, 15, 20),
Rectangle::<i32>::new(144, 76, 15, 20),
Rectangle::<i32>::new(160, 76, 15, 20),
Rectangle::<i32>::new(176, 76, 15, 20),
],
8,
);
Ok(Self { animation })
}
}
impl State for AnimationExample {
type Context = ();
fn update(&mut self, _ctx: &mut Context) -> Result<()> {
self.animation.tick();
Ok(())
}
fn draw(&mut self, ctx: &mut Context, _dt: f64) -> Result<()> {
let mut view = View::new((0.0, 0.0).into(), (1920.0, 1080.0).into());
view.set_zoom(8.0);
window::set_view(ctx, &view);
graphics::draw(
ctx,
&self.animation,
&DrawAnimationParams {
..DrawAnimationParams::default()
},
)?;
Ok(())
}
}
fn main() -> Result<()> {
ContextBuilder::new("Animation", 1920, 1080)
.build_empty()?
.run_with_result(AnimationExample::new)
}