From c7190390ddf3f1e3feed67bb90a59987f28f50d4 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 19 Mar 2023 02:01:16 -0700 Subject: [PATCH] Render simple shapes from example code --- src/main.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/main.rs b/src/main.rs index 4e57af4..90d7a34 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use bevy::prelude::*; +use bevy::sprite::MaterialMesh2dBundle; pub struct GamarjobaPlugin; @@ -41,5 +42,52 @@ fn main() { App::new() .add_plugins(DefaultPlugins) .add_plugin(GamarjobaPlugin) + .add_startup_system(setup) .run(); } + +fn setup( + mut commands: Commands, + mut meshes: ResMut>, + mut materials: ResMut>, +) { + commands.spawn(Camera2dBundle::default()); + + // Circle + commands.spawn(MaterialMesh2dBundle { + mesh: meshes.add(shape::Circle::new(50.).into()).into(), + material: materials.add(ColorMaterial::from(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()) + .into(), + material: materials.add(ColorMaterial::from(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()).into(), + material: materials.add(ColorMaterial::from(Color::TURQUOISE)), + transform: Transform::from_translation(Vec3::new(150., 0., 0.)), + ..default() + }); +} +