Skip to content

Conversation

shaderduck
Copy link

Objective

Fixes #4324

Solution

Used circle from shapes example in #3730


Changelog

Changed

Circle shape instead of square shape sprite for ball.
AABB collision unchanged.

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label May 6, 2022
@james7132 james7132 added C-Examples An addition or correction to our examples C-Feature A new feature, making something new possible and removed S-Needs-Triage This issue needs to be labelled C-Feature A new feature, making something new possible labels May 6, 2022
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work :) Some small suggestions for comments to help this example teach beginners the basic terminology.

@alice-i-cecile
Copy link
Member

bors try

bors bot added a commit that referenced this pull request May 7, 2022
shaderduck and others added 2 commits May 7, 2022 11:13
@Nilirad
Copy link
Contributor

Nilirad commented May 7, 2022

Is the z value in BALL_STARTING_POSITION (or at least the comment above the constant) still relevant now that we have a potential 2D Mesh/Sprite overlap, instead of a sprite/sprite overlap?

@alice-i-cecile
Copy link
Member

Unsure 🤔 I haven't played with the mesh / sprite overlap rules.

Copy link
Contributor

@Nilirad Nilirad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found out that the order in which sprites and 2D meshes are drawn is undefined, just like sprites, so the z layering should remain.

Example code
use bevy::{math::const_vec3, prelude::*, sprite::MaterialMesh2dBundle};

const PADDLE_SIZE: Vec3 = const_vec3!([120.0, 20.0, 0.0]);

const BALL_STARTING_POSITION: Vec3 = const_vec3!([0.0, -50.0, 1.0]);
const BALL_SIZE: Vec3 = const_vec3!([30.0, 30.0, 0.0]);

const PADDLE_COLOR: Color = Color::rgb(0.3, 0.3, 0.7);
const BALL_COLOR: Color = Color::rgb(1.0, 0.5, 0.5);

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>>,
) {
    // Camera
    commands.spawn_bundle(OrthographicCameraBundle::new_2d());

    // Paddle
    commands.spawn().insert_bundle(SpriteBundle {
        transform: Transform {
            translation: BALL_STARTING_POSITION,
            scale: PADDLE_SIZE,
            ..default()
        },
        sprite: Sprite {
            color: PADDLE_COLOR,
            ..default()
        },
        ..default()
    });

    // Ball
    commands.spawn().insert_bundle(MaterialMesh2dBundle {
        mesh: meshes.add(shape::Circle::default().into()).into(),
        material: materials.add(ColorMaterial::from(BALL_COLOR)),
        transform: Transform {
            scale: BALL_SIZE,
            translation: BALL_STARTING_POSITION,
            ..default()
        },
        ..default()
    });
}

So the only thing to do is to change the comment above BALL_STARTING_POSITION to something like:

// We set the z-value of the ball to 1 so it renders on top in the case of overlap.
const BALL_STARTING_POSITION: Vec3 = const_vec3!([0.0, -50.0, 1.0]);

@alice-i-cecile
Copy link
Member

@shaderduck can you rebase this? This would be nice to merge in.

@alice-i-cecile alice-i-cecile added the S-Adopt-Me The original PR author has no intent to complete this work. Pick me up! label Aug 11, 2022
@alice-i-cecile
Copy link
Member

Closing in favor of #5657 :) Thanks for getting this started!

bors bot pushed a commit that referenced this pull request Aug 16, 2022
# 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.
maccesch pushed a commit to Synphonyte/bevy that referenced this pull request Sep 28, 2022
# Objective

- Replace the square with a circle in the breakout example.
- Fixes bevyengine#4324, adopted from bevyengine#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.
james7132 pushed a commit to james7132/bevy that referenced this pull request Oct 28, 2022
# Objective

- Replace the square with a circle in the breakout example.
- Fixes bevyengine#4324, adopted from bevyengine#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.
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# Objective

- Replace the square with a circle in the breakout example.
- Fixes bevyengine#4324, adopted from bevyengine#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.
@shaderduck shaderduck deleted the 4324 branch May 13, 2023 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Examples An addition or correction to our examples S-Adopt-Me The original PR author has no intent to complete this work. Pick me up!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use a circle for the ball in Breakout
4 participants