pub struct Context {
pub gfx: Graphics,
pub audio: Option<Audio>,
pub input: Input,
pub assets: Assets,
pub time: Time,
pub rng: Rng,
pub window: Arc<Window>,
/* private fields */
}Fields§
§gfx: Graphics§audio: Option<Audio>§input: Input§assets: Assets§time: Time§rng: Rng§window: Arc<Window>Implementations§
Source§impl Context
impl Context
pub fn quit(&mut self)
Sourcepub fn canvas_attached(&self) -> bool
pub fn canvas_attached(&self) -> bool
Whether the game’s canvas is in the page, as of the last GameEvent::CanvasAttached.
Always true natively.
Sourcepub fn load_texture(
&mut self,
rel: impl AsRef<Path>,
) -> Result<TextureId, Error>
pub fn load_texture( &mut self, rel: impl AsRef<Path>, ) -> Result<TextureId, Error>
Load a PNG from the asset root. Works on every platform: natively it reads the file and
registers it for hot-reload (game_toolkit_gfx::Graphics::refresh_textures); on the
web it decodes the preloaded bytes.
Sourcepub fn load_sound(
&mut self,
rel: impl AsRef<Path>,
) -> Result<Option<SoundId>, Error>
pub fn load_sound( &mut self, rel: impl AsRef<Path>, ) -> Result<Option<SoundId>, Error>
Load a sound (wav/ogg/flac/mp3) from the asset root. Ok(None) when audio is muted
because the backend failed to initialize.
Sourcepub fn start_audio_if_allowed(&mut self)
pub fn start_audio_if_allowed(&mut self)
Start audio as soon as the browser allows it without another user gesture, e.g. when the host page tells the game the player is back after interacting with the page. The toolkit does this by itself at startup; call it again when a gesture may have happened on the page since (outside the canvas, so the toolkit didn’t see it).
On the web it asks the browser and, if the answer is yes, starts the audio right away or within about 1.5 s (Firefox and WebKit take a moment to say so). Otherwise audio keeps waiting for the first key press, click or touch on the canvas. Natively the device is open from the start and this does nothing.
Auto Trait Implementations§
impl !Freeze for Context
impl !RefUnwindSafe for Context
impl !Sync for Context
impl !UnwindSafe for Context
impl Send for Context
impl Unpin for Context
impl UnsafeUnpin for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.