-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Use a circle for the ball in Breakout #4682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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.
bors try |
Co-authored-by: Alice Cecile <[email protected]>
Co-authored-by: Alice Cecile <[email protected]>
Is the z value in |
Unsure 🤔 I haven't played with the mesh / sprite overlap rules. |
There was a problem hiding this 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]);
@shaderduck can you rebase this? This would be nice to merge in. |
Closing in favor of #5657 :) Thanks for getting this started! |
# 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.
# 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.
# 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.
# 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.
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.