| Crates.io | bevy_2d_line |
| lib.rs | bevy_2d_line |
| version | 0.1.4 |
| created_at | 2024-08-31 12:09:52.040365+00 |
| updated_at | 2025-01-30 15:36:21.539171+00 |
| description | A line rendering plugin for Bevy |
| homepage | |
| repository | https://github.com/piefayth/bevy_2d_line |
| max_upload_size | |
| id | 1358783 |
| size | 139,664 |
Bevy port of https://github.com/mattdesl/three-line-2d
Polylines in a vertex shader; plays nice with projection scale, z-index; supports vertex colors. Does not support picking!
Moving thousands of line endpoints every frame will be slow, because the mesh needs rebuilt when the lines are moved.
Lazily maintained at best!
| Bevy Version | bevy_2d_line Version |
|---|---|
| 0.15 | 0.1.3 |
| 0.14 | 0.1.2 |
Add the following to your Cargo.toml:
[dependencies]
bevy_2d_line = "0.1.3"
LineRenderingPlugin to your Bevy app:use bevy::prelude::*;
use bevy_2d_line::LineRenderingPlugin;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
// Must be added after the `DefaultPlugins`
.add_plugins(LineRenderingPlugin)
.add_systems(Startup, setup)
.run();
}
[!IMPORTANT] The
LineRenderingPluginmust be added after theDefaultPlugins
Line component:use bevy_2d_line::Line;
use bevy::{color::palettes::css::{BLUE, GREEN, RED}, prelude::*};
fn setup(mut commands: Commands) {
commands.spawn(Camera2d::default());
let points = vec![
Vec2::new(-200.0, 0.0),
Vec2::new(0.0, 200.0),
Vec2::new(200.0, 0.0),
];
let colors = vec![
RED.into(),
GREEN.into(),
BLUE.into(),
];
commands.spawn(Line {
points,
colors,
thickness: 5.0,
});
}
Check out the examples directory for more detailed usage:
simple_line.rs: Basic usage of the line renderercurved_line.rs: Rendering a curved line using Bezier curvesTo run an example:
cargo run --example simple_line
Contributions are welcome! Please feel free to submit a Pull Request.