Giving Bevy a try for the first time.
https://taintedcoders.com/bevy/tutorials/pong-tutorial#creating-a-camera
Trying to follow Tainted coders Pong tutorial, running into an issue where the camera seemingly isn't being added to the project?
The tutorial describes: "Instead of a completely black window we get a lighter background." But nothing changed for me so I'm doing something wrong
I'm sure this is a very trivial fix or a typo somewhere, but I'm not sure where I'm going wrong.
Help is appreciated!
Code below:
use bevy::{math::VectorSpace, prelude::*};
#[derive(Component, Default)]
#[require(Transform)]
struct Position(Vec2);
#[derive(Component)]
#[require(Position)]
struct Ball;
const BALL_SIZE: f32 = 5.;
fn project_positions(mut positionables: Query<(&mut Transform, &Position)>) {
for (mut transform, position) in &mut positionables {
transform.translation = position.0.extend(0.)
}
}
fn spawn_camera(mut commands: Commands) {
commands.spawn_empty().insert(Camera2d); // <-- this is the line that is seemingly not working
}
fn spawn_ball(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
println!("spawning ball");
let shape = Circle::new(BALL_SIZE);
let color = Color::srgb(1., 0., 0.);
let mesh = meshes.add(shape);
let material = materials.add(color);
commands
.spawn_empty()
.insert(Position(Vec2::ZERO))
.insert(Ball);
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, (spawn_ball, spawn_camera))
.add_systems(Update, (project_positions))
.run();
}
Tainted Coders
This tutorial will teach you how to build a simple pong game using Bevy as our only dependency. We will use the simple game of pong to teach every major concept you need to create games with Bevy.