#input #web-sys #gamedev #gameloop

web-sys-main-loop

Provides a main loop (or game loop) for web_sys windows

8 releases

0.1.8 Jan 14, 2024
0.1.7 Jan 14, 2024

#858 in Game dev

Download history 20/week @ 2024-01-08 15/week @ 2024-01-15 23/week @ 2024-02-26 12/week @ 2024-03-11 126/week @ 2024-04-01

138 downloads per month

Apache-2.0

17KB
190 lines

Crates.io Version Crates.io License docs.rs

web-sys-main-loop

web-sys-main-loop as per the name suggests provides a main loop (in game development communities often called a game loop), for web-sys based WASM pages, with also providing input handling.

Documentation

Example

use web_sys_main_loop::FrameState;
...
let window = web_sys::window().unwrap();
...
web_sys_main_loop::start(&window, move |frame_state: FrameState| {
    ...
    // Gets the position (X, Y) of the cursor in the window
    // context
    let curr_position = frame_state.mouse_state.get_position();
    ...
});

lib.rs:

web-sys-main-loop provides a main loop (or game loop), and input handling, for a web_sys window.

Example:

use web_sys_main_loop::FrameState;

let window = web_sys::window().unwrap();

web_sys_main_loop::start(&window, move |frame_state: FrameState| {
    ...
    // Gets the position (X, Y) of the cursor in the window
    // context
    let curr_position = frame_state.mouse_state.get_position();
    ...
});

Dependencies

~6.5–9MB
~171K SLoC