2 releases
0.3.1 | Feb 6, 2022 |
---|---|
0.3.0 | Feb 6, 2022 |
#903 in Graphics APIs
1.5MB
1.5K
SLoC
Deno SDL2
Cross platform bindings to SDL2. Have fun!
Features
- Bindings to Video, Graphics, Font and Mixer subsystems. (Uses rodio instead of SDL2_Mixer)
- Built on top of Deno's FFI API. Previous versions used TCP streams.
Example
import { Canvas } from "https://deno.land/x/sdl2/src/canvas.ts";
const canvas = new Canvas({
title: "Hello, Deno!",
height: 800,
width: 600,
centered: true,
fullscreen: false,
hidden: false,
resizable: true,
minimized: false,
maximized: false,
flags: null,
});
canvas.setDrawColor(0, 64, 255, 255);
canvas.clear();
canvas.present();
for await (const event of canvas) {
switch (event.type) {
case "draw":
// Your game logic
// ...
break;
case "mouse_motion":
// Mouse stuff
break;
case "key_down":
// Keyboard stuff
break;
// ...
default:
break;
}
}
Building from source
You need:
deno_bindgen
CLI from themain
branch- Rust nightly toolchain + Cargo (
1.57.0-nightly
) cargo-vcpkg
toolpkg-config
(on *nix) =>brew install pkg-config
deno install -Afq -n deno_bindgen https://deno.land/x/deno_bindgen/cli.ts
cargo install cargo-vcpkg
# build vcpkg dependencies
cargo vcpkg -v build
Build using:
deno_bindgen -- --features "use_vcpkg"
Projects using deno_sdl2
-
...insert your project here
License
MIT
Dependencies
~23MB
~473K SLoC