#Trying to render a Rectangle Grid

3 messages · Page 1 of 1 (latest)

stark dragon
#

Hi,
I'm currently learning Bevy and I'm trying to implement a Conway's Game Of Life using it. My game logic is done and I want to start making the Bevy implementation now. I want to render a Grid and here is the code responsible for it: ```rust

pub fn spawn_grid(
    &self,
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<ColorMaterial>>,
) {
    let square_width = self.window_width as f32 / self.board_width as f32;
    let square = Rectangle::new(square_width, square_width);

    for y in 0..self.board_height {
        for x in 0..self.board_width {
            println!("Spawn at x={x},y={y}");
            commands.spawn(MaterialMesh2dBundle {
                mesh: meshes.add(square).into(),
                material: materials.add(ALIVE_COLOR),
                transform: Transform::default().with_scale(Vec3::splat(200.0)),
                ..default()
            });
        }
    }
}
However, it renders nothing on the window, despite it having a ``Camera2dBundle`` setup elsewhere in the code. The ALIVE_COLOR is a huge green. How can I fix it ?
patent inlet
#

Just in case: try .with_scale(Vec2::splat(200.0).extend(0.)), ?

elder bay
#

However, it renders nothing on the window
It might be rendered but on the other side ? Meshes are only rendered on one side for perf reasons. Try to move your camera on the other side?