sprite.rs 609 Bytes
Newer Older
Simon Goller's avatar
Simon Goller committed
1
2
3
4
5
6
7
8
9
10
11
use crate::components;
use crate::resources;

#[legion::system(for_each)]
#[read_component(components::Position)]
#[read_component(components::Sprite)]
pub fn draw_sprites(
    #[resource] rendering: &resources::Rendering,
    position: &components::Position,
    sprite: &components::Sprite,
) {
12
    let spritesize = rendering.get_image_size(&sprite.image_handle).unwrap();
13
    let upper_left = position.0 - spritesize / 2.0 + sprite.offset;
Simon Goller's avatar
Simon Goller committed
14
    rendering
Simon Goller's avatar
Simon Goller committed
15
16
17
18
19
        .draw_image(
            &sprite.image_handle,
            upper_left.x as f64,
            upper_left.y as f64,
        )
Simon Goller's avatar
Simon Goller committed
20
21
        .unwrap();
}