Skip to content

Commit

Permalink
Consolidate examples
Browse files Browse the repository at this point in the history
  • Loading branch information
rparrett committed Mar 1, 2022
1 parent c6e7923 commit 10b3f0f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 50 deletions.
8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,8 @@ name = "mesh2d_manual"
path = "examples/2d/mesh2d_manual.rs"

[[example]]
name = "circle"
path = "examples/2d/circle.rs"

[[example]]
name = "rect"
path = "examples/2d/rect.rs"
name = "shapes"
path = "examples/2d/shapes.rs"

[[example]]
name = "sprite"
Expand Down
22 changes: 0 additions & 22 deletions examples/2d/circle.rs

This file was deleted.

20 changes: 0 additions & 20 deletions examples/2d/rect.rs

This file was deleted.

52 changes: 52 additions & 0 deletions examples/2d/shapes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use bevy::{prelude::*, sprite::MaterialMesh2dBundle};

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup)
.run();
}

fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());

// Rectangle
commands.spawn_bundle(SpriteBundle {
sprite: Sprite {
color: Color::rgb(0.25, 0.25, 0.75),
custom_size: Some(Vec2::new(50.0, 100.0)),
..Default::default()
},
..Default::default()
});

// Circle
commands.spawn_bundle(MaterialMesh2dBundle {
mesh: meshes.add(shape::Circle::default().into()).into(),
material: materials.add(ColorMaterial::from(Color::PURPLE)),
transform: Transform::from_translation(Vec3::new(-100., 0., 0.))
.with_scale(Vec2::splat(100.0).extend(1.)),
..Default::default()
});

// Hexagon
commands.spawn_bundle(MaterialMesh2dBundle {
mesh: meshes
.add(
shape::RegularPolygon {
sides: 6,
..Default::default()
}
.into(),
)
.into(),
material: materials.add(ColorMaterial::from(Color::TURQUOISE)),
transform: Transform::from_translation(Vec3::new(100., 0., 0.))
.with_scale(Vec2::splat(100.0).extend(1.)),
..Default::default()
});
}
3 changes: 1 addition & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ Example | File | Description
`move_sprite` | [`2d/move_sprite.rs`](./2d/move_sprite.rs) | Changes the transform of a sprite.
`mesh2d` | [`2d/mesh2d.rs`](./2d/mesh2d.rs) | Renders a 2d mesh
`mesh2d_manual` | [`2d/mesh2d_manual.rs`](./2d/mesh2d_manual.rs) | Renders a custom mesh "manually" with "mid-level" renderer apis.
`rect` | [`2d/rect.rs`](./2d/rect.rs) | Renders a rectangle
`circle` | [`2d/circle.rs`](./2d/circle.rs) | Renders a circle
`shapes` | [`2d/shapes.rs`](./2d/shapes.rs) | Renders a rectangle, circle, and hexagon
`sprite` | [`2d/sprite.rs`](./2d/sprite.rs) | Renders a sprite
`sprite_sheet` | [`2d/sprite_sheet.rs`](./2d/sprite_sheet.rs) | Renders an animated sprite
`text2d` | [`2d/text2d.rs`](./2d/text2d.rs) | Generates text in 2d
Expand Down

0 comments on commit 10b3f0f

Please sign in to comment.