raylib/web
driving a raylib frame loop from the browser.
Since: W2
run-main-loop
(run-main-loop [frame : (fn [])
register a per-frame function and hand control to the browser.
| frame | called once per display refresh | |
| fps | target rate; pass 0 for requestAnimationFrame, which is what a | |
| browser wants (it matches the display and stops when the tab is | ||
| hidden). A non-zero rate asks Emscripten to throttle. |
Nothing, and not in the ordinary sense: the underlying `emscripten_set_main_loop` is called with simulate_infinite_loop=1, so it unwinds out of `main` and every statement after this call is unreachable. That is correct on the web rather than regrettable -- there is no window-close event, and closing the tab reclaims the GL context, the textures and the heap in one go, so `close-window` has nothing to do. The consequence that bites: `main`'s stack frame is gone by the first frame, so anything the frame function still refers to has to outlive it. Keep per-frame state in the closure (or a global), never in a local of the function that called this one.
(init-window 800 600 "demo")
(run-main-loop (fn [] : unit
(begin-drawing)
(clear-background (raywhite))
(end-drawing))
0)
Since: W2
cancel-main-loop
(cancel-main-loop :)
stop the registered frame loop.
(cancel-main-loop)
Since: W2
with-web-game-loop
(with-web-game-loop [w title width height fps body])
the web twin of ecs-raylib's with-game-loop.
Since: W2