mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 20:53:53 +00:00
9c972f037e
# Objective A few of these were missed in #10878 ## Solution Fix em
53 lines
1.5 KiB
Rust
53 lines
1.5 KiB
Rust
//! Shows how to render simple primitive shapes with a single color.
|
|
|
|
use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins(DefaultPlugins)
|
|
.add_systems(Startup, setup)
|
|
.run();
|
|
}
|
|
|
|
fn setup(
|
|
mut commands: Commands,
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
|
) {
|
|
commands.spawn(Camera2dBundle::default());
|
|
|
|
// Circle
|
|
commands.spawn(MaterialMesh2dBundle {
|
|
mesh: meshes.add(shape::Circle::new(50.)).into(),
|
|
material: materials.add(Color::PURPLE),
|
|
transform: Transform::from_translation(Vec3::new(-150., 0., 0.)),
|
|
..default()
|
|
});
|
|
|
|
// Rectangle
|
|
commands.spawn(SpriteBundle {
|
|
sprite: Sprite {
|
|
color: Color::rgb(0.25, 0.25, 0.75),
|
|
custom_size: Some(Vec2::new(50.0, 100.0)),
|
|
..default()
|
|
},
|
|
transform: Transform::from_translation(Vec3::new(-50., 0., 0.)),
|
|
..default()
|
|
});
|
|
|
|
// Quad
|
|
commands.spawn(MaterialMesh2dBundle {
|
|
mesh: meshes.add(shape::Quad::new(Vec2::new(50., 100.))).into(),
|
|
material: materials.add(Color::LIME_GREEN),
|
|
transform: Transform::from_translation(Vec3::new(50., 0., 0.)),
|
|
..default()
|
|
});
|
|
|
|
// Hexagon
|
|
commands.spawn(MaterialMesh2dBundle {
|
|
mesh: meshes.add(shape::RegularPolygon::new(50., 6)).into(),
|
|
material: materials.add(Color::TURQUOISE),
|
|
transform: Transform::from_translation(Vec3::new(150., 0., 0.)),
|
|
..default()
|
|
});
|
|
}
|