|
| 1 | +use bevy::{prelude::*, sprite::MaterialMesh2dBundle}; |
| 2 | + |
| 3 | +fn main() { |
| 4 | + App::new() |
| 5 | + .add_plugins(DefaultPlugins) |
| 6 | + .add_startup_system(setup) |
| 7 | + .run(); |
| 8 | +} |
| 9 | + |
| 10 | +fn setup( |
| 11 | + mut commands: Commands, |
| 12 | + mut meshes: ResMut<Assets<Mesh>>, |
| 13 | + mut materials: ResMut<Assets<ColorMaterial>>, |
| 14 | +) { |
| 15 | + commands.spawn_bundle(OrthographicCameraBundle::new_2d()); |
| 16 | + |
| 17 | + // Rectangle |
| 18 | + commands.spawn_bundle(SpriteBundle { |
| 19 | + sprite: Sprite { |
| 20 | + color: Color::rgb(0.25, 0.25, 0.75), |
| 21 | + custom_size: Some(Vec2::new(50.0, 100.0)), |
| 22 | + ..Default::default() |
| 23 | + }, |
| 24 | + ..Default::default() |
| 25 | + }); |
| 26 | + |
| 27 | + // Circle |
| 28 | + commands.spawn_bundle(MaterialMesh2dBundle { |
| 29 | + mesh: meshes.add(shape::Circle::default().into()).into(), |
| 30 | + material: materials.add(ColorMaterial::from(Color::PURPLE)), |
| 31 | + transform: Transform::from_translation(Vec3::new(-100., 0., 0.)) |
| 32 | + .with_scale(Vec2::splat(100.0).extend(1.)), |
| 33 | + ..Default::default() |
| 34 | + }); |
| 35 | + |
| 36 | + // Hexagon |
| 37 | + commands.spawn_bundle(MaterialMesh2dBundle { |
| 38 | + mesh: meshes |
| 39 | + .add( |
| 40 | + shape::RegularPolygon { |
| 41 | + sides: 6, |
| 42 | + ..Default::default() |
| 43 | + } |
| 44 | + .into(), |
| 45 | + ) |
| 46 | + .into(), |
| 47 | + material: materials.add(ColorMaterial::from(Color::TURQUOISE)), |
| 48 | + transform: Transform::from_translation(Vec3::new(100., 0., 0.)) |
| 49 | + .with_scale(Vec2::splat(100.0).extend(1.)), |
| 50 | + ..Default::default() |
| 51 | + }); |
| 52 | +} |
0 commit comments