4 releases (breaking)
0.4.0 | Feb 25, 2024 |
---|---|
0.3.0 | Jul 22, 2023 |
0.2.0 | Mar 8, 2023 |
0.1.0 | Dec 22, 2022 |
#1028 in Game dev
38 downloads per month
9KB
167 lines
Bevy Web Utils
Helpers for working with Bevy on the web
Bindings
This crate includes wasm_bindgen
bindings to some JS snippets that help with various
web tasks, that can be accessed from the micro_bevy_web_utils::bindings
module
orientation_lock(orientation: String);
: Locks the screen to the given orientation. Accepts values defined in the Screen Orientation API. Noop on web platforms that do not support locking orientationorientation_unlock();
: Unlocks the screen orientation. Noop when the orientation is not locked, or on web platforms that do not support locking orientationmake_selector_fullscreen(selector: String);
: Take a query selector, and requests fullscreen mode for the first matching element. Noop if the query selector does not match any elements. Callingmake_selector_fullscreen("canvas")
is the common usagetoggle_selector_fullscreen(selector: String) -> bool;
: Take a query selector and either request fullscreen mode if the window is not in fullscreen, or close fullscreen mode if the window is fullscreenexit_fullscreen();
: Close fullscreen modebind_selector_touch_events(selector: String);
: Bind touch events to the element. This is used in combination with themicro_bevy_web_utils::bevy::emit_touch_events
system to send touch events on touch devicesteardown_selector_touch_events(selector: String);
: Remove touch event bindings for a given elementtake_touch_events() -> String;
: Clears the touch event buffer and returns a serialised JSON array containing all of the events that have been recorded since the last call totake_touch_events
is_fullscreen() -> bool;
: Returns whether an element has fullscreen mode enabledis_touch_device() -> bool;
: Returns whether the device supports touch input
Bevy System
Touch events will only be intercepted after at least one successful call to bind_selector_touch_events
To dispatch touch events recorded by this library, you can add the micro_bevy_web_utils::bevy::emit_touch_events
system. You will then receive
intercepted touch events in any other system that uses the Touches
or EventReader<TouchInput>
resources.
Alternatively, you can manually use the take_touch_events
binding to get all the recorded touch events. They must be handled and/or dispatched after being
taken, or they will be lost - there is no double buffering or equivalent
Dependencies
~19MB
~376K SLoC