Crates.io | macroquad-canvas-2d |
lib.rs | macroquad-canvas-2d |
version | 0.4.0 |
source | src |
created_at | 2021-04-23 00:08:29.632262 |
updated_at | 2024-08-31 15:17:43.003658 |
description | Add canvas functionality to macroquad. |
homepage | |
repository | https://github.com/nicolas-sabbatini/macroquad-canvas-2d |
max_upload_size | |
id | 388350 |
size | 31,658 |
Macroquad Canvas 2D is a simple resolution-handling library that allows you to focus on making your game with a fixed resolution.
It is heavily inspired by Push
Import the library.
use macroquad_canvas_2d::*;
Create a new Canvas2D.
let canvas = Canvas2D::new(WIDTH as f32, HEIGHT as f32);
Draw!
loop {
// Push canvas
canvas.set_camera();
{
// Draw something inside the canvas
// Clear background
clear_background(WHITE);
// Top left
draw_rectangle(0.0, 0.0, 60.0, 60.0, RED);
// Top right
draw_rectangle(WIDTH as f32 - 60.0, 0.0, 60.0, 60.0, GRAY);
// Bottom left
draw_rectangle(0.0, HEIGHT as f32 - 60.0, 60.0, 60.0, GREEN);
// Bottom right
draw_rectangle(WIDTH as f32 - 60.0, HEIGHT as f32 - 60.0, 60.0, 60.0, BLUE);
}
// Pop canvas
set_default_camera();
// Draw canvas on screen
canvas.draw_to_screen();
next_frame().await
}
For more information check out the examples!