A Roc platform for building WASM-4 games.
roc-wasm4 gives Roc apps a high-level W4 API for drawing, input, audio, disk persistence, netplay state, and sprites. Most apps should use a released roc-wasm4 platform bundle directly from GitHub Releases.
- Roc new-compiler nightly, available as
roc - WASM-4 CLI, available as
w4 - A roc-wasm4
.tar.zstplatform bundle URL from the GitHub Releases page
Create app.roc and point platform at a released .tar.zst bundle:
app [main] {
w4: platform "https://github.com/lukewilliamboswell/roc-wasm4/releases/download/0.6/ADeKYHzDvyXSEZjj4wG3qRLTFRYiiEWLuVMPD5S8uBF3.tar.zst",
}
import w4.W4
Model : {}
main = {
init!: || {},
update!: |model| {
W4.text!("Hello from Roc!", { x: 8, y: 8 })
model
},
}Build the cart and run it with WASM-4:
roc build app.roc
w4 run app.wasmBecause roc-wasm4 only declares a wasm32 target, roc build app.roc defaults to writing app.wasm.
For the native WASM-4 runtime, use w4 run-native app.wasm. Native can be much slower than the web runtime, especially for non-optimized builds.
The platform exposes:
w4.W4for WASM-4 drawing, input, audio, disk, random, and utility APIsw4.Spritefor sprite data and blitting helpersw4.Hostfor low-level hosted effects, mostly intended for platform internals
Platform API docs are hosted at lukewilliamboswell.github.io/roc-wasm4/.
This repository includes several example apps:
examples/basic.roc: drawing, text, input, mouse, trace, and tone basicsexamples/snake.roc: a small playable snake gameexamples/rocci-bird.roc: a Rocci Bird demo by Brendan Hansknecht with art by Luke DeVaultexamples/sound.roc: a tone parameter playground
The checked-in examples use the latest released platform bundle so they can be copied into a game project directly:
w4: platform "https://github.com/lukewilliamboswell/roc-wasm4/releases/download/0.6/ADeKYHzDvyXSEZjj4wG3qRLTFRYiiEWLuVMPD5S8uBF3.tar.zst"Contributors testing platform source changes can use the local path shown in CONTRIBUTING.md.
Then build and run the app:
roc build snake.roc
w4 run snake.wasmDrum Roll is a separate demo by Isaac Van Doren. Source and play online.
For a smaller game cart, build the Roc app with size-oriented optimizations:
roc build app.roc --opt=sizeBundle the generated cart with the WASM-4 CLI:
w4 bundle app.wasm --title "My Game" --html my-game.htmlFor native bundles:
w4 bundle app.wasm --title "My Game" \
--windows my-game-windows.exe \
--mac my-game-mac \
--linux my-game-linuxSource-build setup, local checks, docs generation, and release maintenance are covered in CONTRIBUTING.md.



