deno_sdl2

Crates.iodeno_sdl2
lib.rsdeno_sdl2
version0.3.1
sourcesrc
created_at2022-02-06 14:31:10.44538
updated_at2022-02-06 17:20:51.31499
descriptionSDL2 Bindings to Deno
homepage
repositoryhttps://github.com/littledivy/deno_sdl2
max_upload_size
id527861
size3,434,983
Divy Srivastava (littledivy)

documentation

README

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 the main branch
  • Rust nightly toolchain + Cargo (1.57.0-nightly)
  • cargo-vcpkg tool
  • pkg-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

License

MIT

Commit count: 121

cargo fmt