pub struct Canvas2D {
    pub camera: Camera2D,
}
Expand description

This struct represents the canvas, it’s basicaly a wrapper around Camera2D with convinience methods to make life easier.

Note

Deref and DerefMut are implemented, which means you can access fields/methods from Camera2D like so

let canvas = Canvas2D::new(800, 600);
println!("{}", canvas.zoom); // Prints camera zoom

Implementation Detail

There’s a bug that mirrors render target on the Y axis (see https://github.com/not-fl3/macroquad/issues/171#issuecomment-880601087), as a workaround, the render target gets flipped vertically.

Fields

camera: Camera2D

Contains the camera which contains the render texture and other things.

Implementations

Creates a new canvas

Example
let canvas = Canvas2D::new(800, 600);

Returns a reference of the canvas texture

Panics

If the render target is missing.

Returns canvas width.

Panics

If the render target is missing.

Returns canvas height.

Panics

If the render target is missing.

Calculate size and padding of the canvas so it can fit inside of the target and its position is in the center.

Example
let (left_padding, top_padding, dimensions) =
    canvas.calculate_size_and_padding(screen_width(), screen_height());

Calculate size of the canvas so it can fit inside of the target.

Draws canvas with target width/height.

Example
canvas.draw(800, 600);

Draws canvas according to the screen.

It’s basically an alias to

canvas.draw(screen_width(), screen_height());

Methods from Deref<Target = Camera2D>

Returns the screen space position for a 2d camera world space position Screen position in window space - from (0, 0) to (screen_width, screen_height())

Trait Implementations

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.