Struct ggez::graphics::MeshBuilder[][src]

pub struct MeshBuilder { /* fields omitted */ }

A builder for creating Meshes.

This allows you to easily make one Mesh containing many different complex pieces of geometry. They don't have to be connected to each other, and will all be drawn at once.

The following example shows how to build a mesh containing a line and a circle:

This example is not tested
let mesh: Mesh = MeshBuilder::new()
    .line(&[Point2::new(20.0, 20.0), Point2::new(40.0, 20.0)], 4.0)
    .circle(DrawMode::Fill, Point2::new(60.0, 38.0), 40.0, 1.0)
    .build(ctx)
    .unwrap();

A more sophisticated example:

use ggez::{Context, GameResult};
use ggez::graphics::{self, DrawMode, MeshBuilder, Point2};

fn draw_danger_signs(ctx: &mut Context) -> GameResult<()> {
    // Initialize a builder instance.
    let mesh = MeshBuilder::new()
        // Add vertices for 3 lines (in an approximate equilateral triangle).
        .line(
            &[
                Point2::new(0.0, 0.0),
                Point2::new(-30.0, 52.0),
                Point2::new(30.0, 52.0),
                Point2::new(0.0, 0.0),
            ],
            1.0,
        )
        // Add vertices for an exclamation mark!
        .ellipse(DrawMode::Fill, Point2::new(0.0, 25.0), 2.0, 15.0, 2.0)
        .circle(DrawMode::Fill, Point2::new(0.0, 45.0), 2.0, 2.0)
        // Finalize then unwrap. Unwrapping via `?` operator either yields the final `Mesh`,
        // or propagates the error (note return type).
        .build(ctx)?;
    // Draw 3 meshes in a line, 1st and 3rd tilted by 1 radian.
    graphics::draw(ctx, &mesh, Point2::new(50.0, 50.0), -1.0).unwrap();
    graphics::draw(ctx, &mesh, Point2::new(150.0, 50.0), 0.0).unwrap();
    graphics::draw(ctx, &mesh, Point2::new(250.0, 50.0), 1.0).unwrap();
    Ok(())
}

Methods

impl MeshBuilder
[src]

Create a new MeshBuilder.

Important traits for &'a mut R

Create a new mesh for a line of one or more connected segments.

Important traits for &'a mut R

Create a new mesh for a circle.

For the meaning of the tolerance parameter, see here.

Important traits for &'a mut R

Create a new mesh for an ellipse.

For the meaning of the tolerance parameter, see here.

Important traits for &'a mut R

Create a new mesh for a series of connected lines.

Important traits for &'a mut R

Create a new mesh for a closed polygon

Important traits for &'a mut R

Create a new Mesh from a raw list of triangles.

Currently does not support UV's or indices.

Takes the accumulated geometry and load it into GPU memory, creating a single Mesh.

Trait Implementations

impl Debug for MeshBuilder
[src]

Formats the value using the given formatter. Read more

impl Clone for MeshBuilder
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Default for MeshBuilder
[src]

Returns the "default value" for a type. Read more

Auto Trait Implementations

impl Send for MeshBuilder

impl Sync for MeshBuilder