1个稳定版本
| 1.0.0 | 2023年1月29日 | 
|---|
#996在图形API中
26KB
549 行
copper.rs
铜.rs 是一个简单的Rust编写2D游戏库,针对HTML5。
网页中使用
要在网页中使用铜.rs,首先使用 copper.rs-crate 编写您的项目代码,使其具有 crate-type = ["cdylib", "rlib"] 类型,使其依赖于 wasm-bindgen = "0.2",并使用 wasm-pack 的 --target web 构建它。
(lib.rs 的示例)
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn start() {
    // code to run on start here
}
#[wasm_bindgen]
pub fn frame() {
    // code to run on frame here
}
构建完成后,将生成一个包含 .wasm-文件和一个 <crate-name>.js(以及其他文件)的目录。请使此目录可访问,以及 copper.js(直接从最新版本从仓库下载文件)。
(网页的示例)
<!doctype html>
<html>
    <head>
        <script src="copper.js"></script> <!-- the downloaded copper.js -->
        <script>
            // load the generated game WASM and run it
            copperStartWasm("./pkg/<crate-name>.js"); // change "./pkg/<crate-name>.js" to the actual name of the file
        </script>
    </head>
    <!-- "touch-action: none;" disables multi-touch gestures -->
    <body style="margin: 0px; overflow: hidden; touch-action: none;">
        <!-- make the canvas fill the entire screen -->
        <canvas id="game_canvas" style="width: 100vw; height: 100vh;"></canvas>
    </body>
</html>
依赖项
~0.7–1.4MB
~28K SLoC