logo
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

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.

Trait Implementations

Formats the value using the given formatter. Read more
Method to retrieve the context type.
Method to retrieve the context type.
Method to retrieve the context type.
Method to retrieve the context type as mutable.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Method to retrieve the context type.
Method to retrieve the context type as mutable.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.