Native windows, 2D graphics, audio, Dear ImGui and RmlUi for Node.js, built on SFML 3.1.0.
Website · Core guides · ImGui guide · RmlUi guide · Native extensions · API reference
This repository is a Rush monorepo for the published bindings and their shared native layer:
| Package | Purpose |
|---|---|
sfml.js |
Native windows, typed events, 2D graphics, audio and SFML-style networking for Node.js. |
sfml.js-imgui |
Dear ImGui 1.91.9b integration for sfml.js, following imgui-sfml 3.0: debug panels, scene inspectors and editor controls in a native window. |
sfml.js-rmlui |
RmlUi 6.3 document UI in native windows: RML/RCSS, data binding, Node/Lua scripting, fonts, SVG/Lottie and the Debugger. |
sfml.js-interop |
Shared native headers and SFML SDK paths, consumed by the bindings and by third-party native extensions. Applications do not need it directly. |
The core modules cover System, Window, Graphics, Audio and Network; TypeScript declarations are included. Numeric values and resource views use typed arrays, and rendering records state snapshots and submits commands in batches. See core concepts for ownership, asynchronous loading and rendering behavior.
npm install sfml.js sfml.js-imguiInstall only sfml.js for the core binding, or add sfml.js-rmlui for document UI:
npm install sfml.js sfml.js-rmluiInstallation compiles native addons and downloads the matching SFML libraries, so prepare Python and a C++20 toolchain first:
| Platform | Targets | Build tools |
|---|---|---|
| macOS 13+ | x64, arm64 | Xcode Command Line Tools |
| Linux | x64 | GCC or Clang, make, X11, OpenGL and audio development libraries |
| Windows | x64, ia32 | Visual Studio 2022 C++ Build Tools |
The packages declare Node.js ^18.19.0 || >=20.5.0; CI runs Node.js 20 and 22 on Linux, macOS and Windows. See the platform requirements for exact commands.
Save this as hello.cjs and run node hello.cjs in a graphical session:
const sf = require('sfml.js');
const window = new sf.RenderWindow(
new sf.VideoMode(new sf.Vector2u(800, 600)),
'Hello, sfml.js',
);
const circle = new sf.CircleShape({ radius: 80 });
circle.setPosition(new sf.Vector2f(320, 220));
circle.setFillColor(new sf.Color(76, 190, 110));
window.setFramerateLimit(60);
function frame() {
window.handleEvents({
Closed: () => window.close(),
KeyPressed: event => {
if (event.code === sf.Keyboard.Key.Escape) window.close();
},
});
if (!window.isOpen()) return;
window.clear(new sf.Color(24, 28, 32));
window.draw(circle);
window.display();
setImmediate(frame);
}
frame();setImmediate() lets Node.js process I/O between frames; display() is synchronous and can wait for the frame limit or vertical sync. File loading uses promises. More patterns are in the core package README and the quick start.
sfml.js-imgui is a peer of sfml.js. Forward every window event, then declare widgets between SFML.Update and SFML.Render:
const sf = require('sfml.js');
const { ImGui, SFML } = require('sfml.js-imgui');
const window = new sf.RenderWindow(
new sf.VideoMode(new sf.Vector2u(800, 600)),
'ImGui counter',
);
window.setFramerateLimit(60);
const clock = new sf.Clock();
let clicks = 0;
SFML.Init(window);
try {
while (window.isOpen()) {
let event;
while ((event = window.pollEvent()) !== undefined) {
SFML.ProcessEvent(window, event);
if (event.is('Closed')) window.close();
}
SFML.Update(window, clock.restart().asSeconds());
if (ImGui.Begin('Controls')) {
if (ImGui.Button('Count')) clicks++;
ImGui.TextUnformatted(`Clicks: ${clicks}`);
}
ImGui.End();
window.clear(sf.Color.Black);
SFML.Render(window);
window.display();
}
} finally {
SFML.Shutdown(window);
window.close();
}Use SFML.GetIO().wantCaptureMouse and wantCaptureKeyboard to gate scene input. The full frame loop, input routing and shutdown rules are explained in the ImGui quick start.
sfml.js-rmlui renders RML/RCSS documents in an SFML window. It supports native data models, Node/Lua document scripts, FreeType/HarfBuzz/bitmap fonts, SVG/Lottie elements and the Debugger. RML and RCSS are RmlUi's own languages; browser DOM APIs and arbitrary browser CSS are unavailable. Follow the RmlUi quick start for the frame loop, input and resource ownership.
RmlUi, FreeType, rlottie and HarfBuzz build sources ship trimmed and pinned in packages/sfml.js-rmlui/vendor. Installation validates them locally; Lua and LunaSVG retain their download steps. Original sample fonts, textures, documents and visual test data are prepared separately when examples or runtime tests start, with extra IME fonts remaining optional.
Playable breakout using shapes, keyboard input and a JavaScript game loop:
git clone https://github.com/XadillaX/sfml.js.git
cd sfml.js
node tools/bootstrap.cjs
node packages/sfml.js/examples/breakout.cjs
node packages/sfml.js-imgui/examples/demo.cjs
npm --prefix packages/sfml.js-rmlui run examples -- variables- Core: feature examples, official examples, games and applications
- ImGui: widget demo, scene inspector and workbench
- RmlUi: original samples, native games and VisualTests
External projects: node-sfml-demos (Bomberman, Breakout, Tetris and more), 16-sfml.js-games-ported and play-nes, a desktop NES emulator built with sfml.js.
Guides ship in the repository in English, Simplified Chinese, Japanese and Korean:
| Topic | Guides |
|---|---|
| Core binding | Quick start · Core concepts · API guide · Development |
| ImGui | Quick start · Widgets · Layout · Tables, menus and modals |
| RmlUi | Quick start · Data models · Scripts · Fonts · Rendering |
| Native extensions | Interop contract |
The website publishes these guides plus TypeDoc signatures for sfml.js, sfml.js-imgui and sfml.js-rmlui in all four languages. Package READMEs: sfml.js, sfml.js-imgui, sfml.js-rmlui, sfml.js-interop.
Prepare Node.js 20 or 22, Python and a C++20 toolchain using the platform requirements. From a clone, run:
node tools/bootstrap.cjsThis installs the pinned Rush/pnpm dependencies, downloads native libraries, builds the packages and website, and generates the root clangd compilation database. The website is a private Rush project in site:
npm --prefix site run dev
node common/scripts/install-run-rush.js build --to sfml-js-site
npm --prefix site testThe production website is generated in site/build/site. API comments and runnable examples stay in their owning packages.
Refresh the pinned RmlUi build sources or prepare its resources explicitly:
npm --prefix packages/sfml.js-rmlui run update:rmlui
npm --prefix packages/sfml.js-rmlui run update:freetype
npm --prefix packages/sfml.js-rmlui run update:rlottie
npm --prefix packages/sfml.js-rmlui run update:harfbuzz
npm --prefix packages/sfml.js-rmlui run download:examples
npm --prefix packages/sfml.js-rmlui run download:ime-fontsAppend -- --version X.Y.Z to select an upstream release; GitHub release resolution requires gh. Local archives, checksums and resource caching are described in the RmlUi package README. npm --prefix packages/sfml.js-rmlui run examples -- --list lists samples without downloading their assets.
Use the development guide to prepare your environment. Pull requests for fixes, documentation and examples are welcome. Include a runnable reproduction with bug reports, together with the Node.js version, operating system and architecture.
Thanks goes to these wonderful people (emoji key):
Khaidi Chu 🚧 💻 |
NuriYuri 💻 |
Hanz 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
MIT.
