百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

macroquad

> 编程语言
开源

Rust 中的跨平台游戏引擎。

4.6K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Rust 中的跨平台游戏引擎。

macroquad

macroquad is a simple and easy to use game library for Rust programming language, heavily inspired by raylib.

Features

  • Same code for all supported platforms, no platform dependent defines required.
  • Efficient 2D rendering with automatic geometry batching.
  • Minimal amount of dependencies: build after cargo clean takes only 16s on x230(~6 years old laptop).
  • Immediate mode UI library included.
  • Single command deploy for both WASM and Android.

Supported Platforms

  • PC: Windows/Linux/macOS;
  • HTML5;
  • Android;
  • IOS.

Build Instructions

Setting Up a Macroquad Project

Macroquad is a normal rust dependency, therefore an empty macroquad project may be created with:

# Create empty cargo project
cargo init --bin

Add macroquad as a dependency to Cargo.toml:


[dependencies]
macroquad = "0.4"

Put some macroquad code in src/main.rs:

use macroquad::prelude::*;

#[macroquad::main("BasicShapes")]
async fn main() {
    loop {
        clear_background(RED);

        draw_line(40.0, 40.0, 100.0, 200.0, 15.0, BLUE);
        draw_rectangle(screen_width() / 2.0 - 60.0, 100.0, 120.0, 60.0, GREEN);
        draw_circle(screen_width() - 30.0, screen_height() - 30.0, 15.0, YELLOW);

        draw_text("IT WORKS!", 20.0, 20.0, 30.0, DARKGRAY);

        next_frame().await
    }
}

And to run it natively:

cargo run

For more examples take a look at Macroquad examples folder

Linux

# ubuntu system dependencies
apt install pkg-config libx11-dev libxi-dev libgl1-mesa-dev libasound2-dev

# fedora system dependencies
dnf install libX11-devel libXi-devel mesa-libGL-devel alsa-lib-devel

# arch linux system dependencies
pacman -S pkg-config libx11 libxi mesa-libgl alsa-lib

Windows

On windows both MSVC and GNU target are supported, no additional dependencies required.

Also cross-compilation to windows from linux is supported:

rustup target add x86_64-pc-windows-gnu

cargo run --target x86_64-pc-windows-gnu

WASM

rustup target add wasm32-unknown-unknown
cargo build --target wasm32-unknown-unknown

This will produce .wasm file in target/wasm32-unknown-unknown/debug/CRATENAME.wasm or in target/wasm32-unknown-unknown/release/CRATENAME.wasm if built with --release.

And then use the following .html to load it:

index.html
…

One of the ways to server static .wasm and .html:

cargo install basic-http-server
basic-http-server .

IOS

To run on the simulator:

…

For details and instructions on provisioning for real iphone, check https://macroquad.rs/articles/ios/

Tips Adding the following snippet to your Cargo.toml ensures that all dependencies compile in release even in debug mode. In macroquad, this has the effect of making images load several times faster and your applications much more performant, while keeping compile times miraculously low.
[profile.dev.package.'*']
opt-level = 3

async/await

While macroquad attempts to use as few Rust-specific concepts as possible, .await in all examples looks a bit scary. Rust's async/await is used to solve just one problem - cross platform main loop organization.

Details

The problem: on WASM and android it's not really easy to organize the main loop like this:

fn main() {
    // do some initialization

    // start main loop
    loop {
        // handle input

        // update logic

        // draw frame
    }
}

It is fixable on Android with threads, but on web there is not way to "pause" and "resume" WASM execution, so no WASM code should block ever. While that loop is blocking for the entire game execution! The C++ solution for that problem: https://kripken.github.io/blog/wasm/2019/07/16/asyncify.html

But in Rust we have async/await. Rust's futures are basically continuations - future's stack may be stored into a variable to pause/resume execution of future's code at a later point.

async/await support in macroquad comes without any external dependencies - no runtime, no executors and futures-rs is not involved. It's just a way to preserve main's stack on WASM and keep the code cross platform without any WASM-specific main loop.

Community

  • Quads Discord server - a place to chat with the library's devs and other community members.
  • Awesome Quads - a curated list of links to miniquad/macroquad-related code & resources.

Platinum sponsors

Macroquad is supported by:

SourceGear

GitHub Issues· 0 开放

在 GitHub 查看全部

暂无开放 Issues,或尚未同步最近议题。

核心特点

  • •Same code for all supported platforms, no platform dependent defines required.
  • •Efficient 2D rendering with automatic geometry batching.
  • •Minimal amount of dependencies: build after cargo clean takes only 16s on x230(~6 years old laptop).
  • •Immediate mode UI library included.
  • •Single command deploy for both WASM and Android.
  • •PC: Windows/Linux/macOS;
  • •Android;
  • •Quads Discord server - a place to chat with the library's devs and other community members.
  • •Awesome Quads - a curated list of links to miniquad/macroquad-related code & resources.

> 标签

Rustandroidgame-engineiosrust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言