We can also add a regular polygon to our app.
use bevy::{
app::{App, Startup},
asset::Assets,
core_pipeline::core_2d::Camera2dBundle,
ecs::system::{Commands, ResMut},
prelude::default,
render::mesh::{shape::RegularPolygon, Mesh},
sprite::ColorMesh2dBundle,
DefaultPlugins,
};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(ColorMesh2dBundle {
mesh: meshes.add(RegularPolygon::new(50., 5).into()).into(),
..default()
});
}
The new function of RegularPolygon accepts two parameters, which are the radius and the number of sides of the RegularPolygon.
Result:
➡️ Next: Shapes With Transformation
📘 Back: Table of contents