Struct ggez::graphics::MeshBuilder [−][src]
pub struct MeshBuilder { /* fields omitted */ }
A builder for creating Mesh
es.
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:
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]
impl MeshBuilder
pub fn new() -> Self
[src]
pub fn new() -> Self
Create a new MeshBuilder.
ⓘImportant traits for &'a mut Rpub fn line(&mut self, points: &[Point2], width: f32) -> &mut Self
[src]
pub fn line(&mut self, points: &[Point2], width: f32) -> &mut Self
Create a new mesh for a line of one or more connected segments.
ⓘImportant traits for &'a mut Rpub fn circle(
&mut self,
mode: DrawMode,
point: Point2,
radius: f32,
tolerance: f32
) -> &mut Self
[src]
pub fn circle(
&mut self,
mode: DrawMode,
point: Point2,
radius: f32,
tolerance: f32
) -> &mut Self
Create a new mesh for a circle.
For the meaning of the tolerance
parameter, see here.
ⓘImportant traits for &'a mut Rpub fn ellipse(
&mut self,
mode: DrawMode,
point: Point2,
radius1: f32,
radius2: f32,
tolerance: f32
) -> &mut Self
[src]
pub fn ellipse(
&mut self,
mode: DrawMode,
point: Point2,
radius1: f32,
radius2: f32,
tolerance: f32
) -> &mut Self
Create a new mesh for an ellipse.
For the meaning of the tolerance
parameter, see here.
ⓘImportant traits for &'a mut Rpub fn polyline(&mut self, mode: DrawMode, points: &[Point2]) -> &mut Self
[src]
pub fn polyline(&mut self, mode: DrawMode, points: &[Point2]) -> &mut Self
Create a new mesh for a series of connected lines.
ⓘImportant traits for &'a mut Rpub fn polygon(&mut self, mode: DrawMode, points: &[Point2]) -> &mut Self
[src]
pub fn polygon(&mut self, mode: DrawMode, points: &[Point2]) -> &mut Self
Create a new mesh for a closed polygon
ⓘImportant traits for &'a mut Rpub fn triangles(&mut self, triangles: &[Point2]) -> &mut Self
[src]
pub fn triangles(&mut self, triangles: &[Point2]) -> &mut Self
Create a new Mesh
from a raw list of triangles.
Currently does not support UV's or indices.
pub fn build(&self, ctx: &mut Context) -> GameResult<Mesh>
[src]
pub fn build(&self, ctx: &mut Context) -> GameResult<Mesh>
Takes the accumulated geometry and load it into GPU memory,
creating a single Mesh
.
Trait Implementations
impl Debug for MeshBuilder
[src]
impl Debug for MeshBuilder
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Clone for MeshBuilder
[src]
impl Clone for MeshBuilder
fn clone(&self) -> MeshBuilder
[src]
fn clone(&self) -> MeshBuilder
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Default for MeshBuilder
[src]
impl Default for MeshBuilder
Auto Trait Implementations
impl Send for MeshBuilder
impl Send for MeshBuilder
impl Sync for MeshBuilder
impl Sync for MeshBuilder