From f9104b73a2980717a0745c108d47c1ea573ddf2d Mon Sep 17 00:00:00 2001 From: Tomasz Galkowski Date: Tue, 16 Aug 2022 23:18:54 +0000 Subject: [PATCH] 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. --- examples/games/breakout.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/games/breakout.rs b/examples/games/breakout.rs index 5677a4bf90337..c2d592b4c7e3c 100644 --- a/examples/games/breakout.rs +++ b/examples/games/breakout.rs @@ -3,6 +3,7 @@ use bevy::{ prelude::*, sprite::collide_aabb::{collide, Collision}, + sprite::MaterialMesh2dBundle, time::FixedTimestep, }; @@ -171,7 +172,12 @@ struct Scoreboard { } // Add the game's entities to our world -fn setup(mut commands: Commands, asset_server: Res) { +fn setup( + mut commands: Commands, + mut meshes: ResMut>, + mut materials: ResMut>, + asset_server: Res, +) { // Camera commands.spawn_bundle(Camera2dBundle::default()); @@ -203,16 +209,10 @@ fn setup(mut commands: Commands, asset_server: Res) { commands .spawn() .insert(Ball) - .insert_bundle(SpriteBundle { - transform: Transform { - scale: BALL_SIZE, - translation: BALL_STARTING_POSITION, - ..default() - }, - sprite: Sprite { - color: BALL_COLOR, - ..default() - }, + .insert_bundle(MaterialMesh2dBundle { + mesh: meshes.add(shape::Circle::default().into()).into(), + material: materials.add(ColorMaterial::from(BALL_COLOR)), + transform: Transform::from_translation(BALL_STARTING_POSITION).with_scale(BALL_SIZE), ..default() }) .insert(Velocity(INITIAL_BALL_DIRECTION.normalize() * BALL_SPEED));