You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Trac3r-rust/src/sprite.rs

34 lines
1.3 KiB

use crate::vertex_2d::ColoredVertex2D;
#[derive(Debug, Clone)]
pub struct Sprite {
vertices: [ColoredVertex2D; 6],
color: [f32; 4],
}
impl Sprite {
pub fn new(position: (f32, f32), size: (u32, u32)) -> Sprite {
Sprite::new_with_color(position, size, (0.,0.,0.,0.))
}
pub fn new_with_color(position: (f32, f32), size: (u32, u32), color: (f32, f32, f32, f32)) -> Sprite {
let size = (size.0 as f32, size.1 as f32);
let color = [color.0, color.1, color.2, color.3];
Sprite {
vertices: [
ColoredVertex2D { position: [ position.0, position.1 ], color }, // top left
ColoredVertex2D { position: [ position.0, position.1 + size.1], color }, // bottom left
ColoredVertex2D { position: [ position.0 + size.0, position.1 + size.1 ], color }, // bottom right
ColoredVertex2D { position: [ position.0, position.1 ], color }, // top left
ColoredVertex2D { position: [ position.0 + size.0, position.1 + size.1 ], color }, // bottom right
ColoredVertex2D { position: [ position.0 + size.0, position.1 ], color }, // top right
],
color: color,
}
}
}