
Simple and Fast Multimedia Library
SFML の Node.js バインディング。JavaScript や TypeScript でネイティブウィンドウを開き、2D グラフィックスを描画し、音声を再生できます。
npm install sfml.jsmacOS / Windows / Linux
SFML 3.1 ベース · SFML についてRenderWindow · CircleShape · Color
RenderWindow を作り、CircleShape を描いてフレームを表示します。SFML がウィンドウと描画を、JavaScript がループを担当します。TypeScript の型定義も同梱しています。
クイックスタートへデスクトップのグラフィカル環境で実行してください。Esc で終了します。setImmediate によりフレーム間で Node.js の I/O を処理できます。
node hello.cjsconst sf = require('sfml.js');
const win = 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(108, 190, 82));
win.setFramerateLimit(60);
function frame() {
win.handleEvents({
Closed: () => win.close(),
KeyPressed: e => {
if (e.code === sf.Keyboard.Key.Escape) win.close();
},
});
if (!win.isOpen()) return;
win.clear(new sf.Color(24, 28, 32));
win.draw(circle);
win.display();
setImmediate(frame);
}
frame();グラフィックス、文字、シェーダー、録音、ネットワーク通信のサンプルを実行できます。
SFML の C++ ドキュメントと型リファレンスを併せて参照できます。Promise、共有型付き配列、リソースの寿命、Node.js の描画バッチ処理は、このサイトのガイドで解説します。