#input #web-sys #gamedev #cursor-position #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

#846 in Game dev

Download history 7/week @ 2024-07-06 64/week @ 2024-07-27 1/week @ 2024-08-03 1/week @ 2024-09-21 78/week @ 2024-09-28

79 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–9.5MB
~174K SLoC