Skip to content

Latest commit

 

History

History
43 lines (33 loc) · 1.33 KB

quads.md

File metadata and controls

43 lines (33 loc) · 1.33 KB

Quads

In addition to Circle, we can add rectangles to our app. A rectangle in Bevy is called a Quad.

use bevy::{
    app::{App, Startup},
    asset::Assets,
    core_pipeline::core_2d::Camera2dBundle,
    ecs::system::{Commands, ResMut},
    prelude::default,
    render::mesh::{shape::Quad, Mesh},
    sprite::ColorMesh2dBundle,
    DefaultPlugins,
};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
    commands.spawn(Camera2dBundle::default());

    commands.spawn(ColorMesh2dBundle {
        mesh: meshes.add(Quad::new((150., 100.).into()).into()).into(),
        ..default()
    });
}

The function Quad::new accepts a Vec2, which defines the width and the height of the Quad.

Result:

Quads

➡️ Next: Regular Polygons

📘 Back: Table of contents