-
Notifications
You must be signed in to change notification settings - Fork 0
/
ortho_tileset_animated.rs
58 lines (41 loc) · 1.36 KB
/
ortho_tileset_animated.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
use std::path::Path;
use coarsetime::Instant;
use macroquad::color::LIGHTGRAY;
use macroquad::input::{is_key_down, KeyCode};
use macroquad::math::Rect;
use macroquad::window::{clear_background, next_frame, screen_height, screen_width};
use tiled::Loader;
use macroquad_tiled_redux::TileSet;
#[macroquad::main("Texture")]
async fn main() {
let path = Path::new("assets/horse.tsx");
let tileset = Loader::new()
.load_tsx_tileset(path)
.expect("Couldn't load tileset");
println!("{:?}", tileset);
let mqts = TileSet::new_async(tileset)
.await
.expect("Couldn't load Tileset");
let sprite_id = 0;
let w = mqts.tileset.tile_width as f32;
let h = mqts.tileset.tile_height as f32;
let mut ani_state = mqts.make_animated(sprite_id, Instant::now(), false);
let animation = mqts.animations.get(&sprite_id);
ani_state.playing = true;
loop {
clear_background(LIGHTGRAY);
if let Some(animation) = animation {
let dest = Rect::new(
screen_width() / 2.0 - w / 2.0,
screen_height() / 2.0 - h / 2.0,
w,
h);
ani_state.update(animation, Instant::now());
mqts.ani_spr(&mut ani_state, dest);
}
if is_key_down(KeyCode::Q) {
break;
}
next_frame().await
}
}