INNER CODE UNIT · Rust
add_collider_lines
CleanCut/rusty_engine · src/game.rs:157
fn add_collider_lines(commands: &mut Commands, sprite: &mut Sprite) {
// Add the collider lines, a visual representation of the sprite's collider
let points = sprite.collider.points(); // will be empty vector if NoCollider
if points.len() >= 2 {
let mut shape_path = ShapePath::new().move_to(points[0]);
for point in &points[1..] {
shape_path = shape_path.line_to(*point);
}
shape_path = shape_path.close();
let transform = sprite.bevy_transform();
let line_width = 1.0 / transform.scale.x;
commands
.spawn((
ShapeBuilder::with(&shape_path)
.stroke(Stroke::new(Color::WHITE, line_width))
.build(),
transform,
))