#game #shapes #gamedev #graphics #bevy

bevy_prototype_lyon

Draw 2D shapes and paths in the Bevy game engine

8 releases

new 0.3.1 Apr 19, 2021
0.3.0 Apr 10, 2021
0.2.0 Jan 26, 2021
0.1.5 Jan 3, 2021
0.1.2 Sep 21, 2020

#23 in Game dev

Download history 12/week @ 2020-12-24 66/week @ 2020-12-31 69/week @ 2021-01-07 69/week @ 2021-01-14 87/week @ 2021-01-21 74/week @ 2021-01-28 71/week @ 2021-02-04 72/week @ 2021-02-11 57/week @ 2021-02-18 143/week @ 2021-02-25 101/week @ 2021-03-04 81/week @ 2021-03-11 46/week @ 2021-03-18 53/week @ 2021-03-25 55/week @ 2021-04-01 152/week @ 2021-04-08

393 downloads per month
Used in 2 crates (via heron_debug)

MIT license

160KB
921 lines

Bevy + Lyon = ❤

Crates.io Crates.io Downloads GitHub Repo stars CI Bevy tracking

bevy_prototype_lyon enables Bevy users to draw 2D shapes and paths, like triangles, circles, rectangles, lines, arcs and beziers.

Try out the live demo! Regular polygon demo

How does it work?

Currently Bevy does not support drawing custom shapes in an easy way. This crate uses a variation of Bevy's SpriteBundle with custom meshes to draw shapes. The lyon crate is used to generate those custom mesh.

Changelog

0.3.1

  • Restored support for bevy_webgl2 (lost on v0.3.0).

0.3.0

  • Support for Bevy 0.5
  • Shapes with outline

0.2.0

  • Complete API reworking
  • Regular polygon support
  • Extensible shape system through Geometry trait

0.1.5

  • updated dependency to lyon_tessellation v0.17
  • with lyon_tessellation v0.17, unfortunately rectangles with rounded borders are no longer supported.
  • Quad, Triangle and Polyline have been substituted by a general-purpose Polygon shape.

Usage

Add the following line in your cargo.toml manifest file, under the [dependencies] section:

bevy_prototype_lyon = "0.3.1"

Then, you can start by drawing simple shapes:

use bevy::prelude::*;
use bevy_prototype_lyon::prelude::*;

fn main() {
    App::build()
        .insert_resource(Msaa { samples: 8 })
        .add_plugins(DefaultPlugins)
        .add_plugin(ShapePlugin)
        .add_startup_system(setup.system())
        .run();
}

fn setup(mut commands: Commands) {
    let shape = shapes::RegularPolygon {
        sides: 6,
        feature: shapes::RegularPolygonFeature::Radius(200.0),
        ..shapes::RegularPolygon::default()
    };

    commands.spawn_bundle(OrthographicCameraBundle::new_2d());
    commands.spawn_bundle(GeometryBuilder::build_as(
        &shape,
        ShapeColors::outlined(Color::TEAL, Color::BLACK),
        DrawMode::Outlined {
            fill_options: FillOptions::default(),
            outline_options: StrokeOptions::default().with_line_width(10.0),
        },
        Transform::default(),
    ));
}

Don't forget to check out the examples to learn more!

Bevy versions supported

I strive to support the latest version of Bevy. Support for a version of Bevy is dropped as soon as a new one is released.

The following table shows the latest version of bevy_prototype_lyon that supports a certain version of Bevy.

bevy bevy_prototype_lyon
0.5 0.3
0.4 0.2

Dependencies

~13–25MB
~420K SLoC