pub struct Context {
pub fs: Filesystem,
pub gfx: GraphicsContext,
pub time: TimeContext,
pub audio: AudioContext,
pub keyboard: KeyboardContext,
pub mouse: MouseContext,
pub gamepad: GamepadContext,
pub continuing: bool,
pub quit_requested: bool,
/* private fields */
}
Expand description
A Context
is an object that holds on to global resources.
It basically tracks hardware state such as the screen, audio
system, timers, and so on. Generally this type can not
be shared/sent between threads and only one Context
can exist at a time. Trying
to create a second one will fail. It is fine to drop a Context
and create a new one, but this will also close and re-open your
game’s window.
Most functions that interact with the hardware, for instance
drawing things, playing sounds, or loading resources will need
to access one, or rarely even two, of its sub-contexts.
It is an error to create some type that
relies upon a Context
, such as Image
, and then drop the Context
and try to draw the old Image
with the new Context
.
The fields in this struct used to be basically undocumented features,
only here to make it easier to debug, or to let advanced users
hook into the guts of ggez and make it do things it normally
can’t. Now that ggez
’s module-level functions, taking the whole Context
have been deprecated, calling their methods directly is recommended.
Fields
fs: Filesystem
Filesystem state.
gfx: GraphicsContext
Graphics state.
time: TimeContext
Timer state.
audio: AudioContext
Audio context.
keyboard: KeyboardContext
Keyboard input context.
mouse: MouseContext
Mouse input context.
gamepad: GamepadContext
Gamepad input context.
continuing: bool
Controls whether or not the event loop should be running.
This is internally controlled by the outcome of quit_event
,
requested through event::request_quit()
.
quit_requested: bool
Whether or not a quit_event
has been requested.
Set this with ggez::event::request_quit()
.
It’s exposed here for people who want to roll their own event loop.
Implementations
sourceimpl Context
impl Context
sourcepub fn request_quit(&mut self)
pub fn request_quit(&mut self)
Attempts to terminate the ggez::event::run()
loop by requesting a
quit_event
at the very start of the next frame. If this event
returns Ok(false)
, then Context.continuing
is set to false
and the loop breaks.