11 unstable releases (3 breaking)

0.4.0 Aug 31, 2024
0.3.1 Feb 13, 2024
0.2.3 Sep 25, 2022
0.2.2 Mar 3, 2022
0.1.1 Apr 23, 2021

#325 in Game dev

Apache-2.0

13KB
182 lines

Macroquad Canvas 2D

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

How to use it

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!

TODO

  • ✅ Function to transform canvas coordinates to screen coordinates.
  • ✅ Mouse position, and transform.
  • ✅ Camera movement and rotation.
    • ◻ Add camera constaint.
    • ◻ Add camera effects like shake.
  • ◻ Simple post processing effects.

Dependencies

~12MB
~265K SLoC