Skip to content

Commit f9104b7

Browse files
committed
Use circle for breakout example (#5657)
# Objective - Replace the square with a circle in the breakout example. - Fixes #4324, adopted from #4682 by @shaderduck. ## Solution - Uses the Mesh2D APIs to draw a circle. The collision still uses the AABB algorithm, but it seems to be working fine, and I haven't seen any odd looking cases.
1 parent f20c9ee commit f9104b7

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

examples/games/breakout.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use bevy::{
44
prelude::*,
55
sprite::collide_aabb::{collide, Collision},
6+
sprite::MaterialMesh2dBundle,
67
time::FixedTimestep,
78
};
89

@@ -171,7 +172,12 @@ struct Scoreboard {
171172
}
172173

173174
// Add the game's entities to our world
174-
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
175+
fn setup(
176+
mut commands: Commands,
177+
mut meshes: ResMut<Assets<Mesh>>,
178+
mut materials: ResMut<Assets<ColorMaterial>>,
179+
asset_server: Res<AssetServer>,
180+
) {
175181
// Camera
176182
commands.spawn_bundle(Camera2dBundle::default());
177183

@@ -203,16 +209,10 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
203209
commands
204210
.spawn()
205211
.insert(Ball)
206-
.insert_bundle(SpriteBundle {
207-
transform: Transform {
208-
scale: BALL_SIZE,
209-
translation: BALL_STARTING_POSITION,
210-
..default()
211-
},
212-
sprite: Sprite {
213-
color: BALL_COLOR,
214-
..default()
215-
},
212+
.insert_bundle(MaterialMesh2dBundle {
213+
mesh: meshes.add(shape::Circle::default().into()).into(),
214+
material: materials.add(ColorMaterial::from(BALL_COLOR)),
215+
transform: Transform::from_translation(BALL_STARTING_POSITION).with_scale(BALL_SIZE),
216216
..default()
217217
})
218218
.insert(Velocity(INITIAL_BALL_DIRECTION.normalize() * BALL_SPEED));

0 commit comments

Comments
 (0)