#cursor-position #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

#1045 in Game dev

Download history 65/week @ 2024-07-29 44/week @ 2024-09-30

61 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

~7.5–10MB
~182K SLoC