pub struct GameContext { /* private fields */ }Expand description
Runtime context passed to the game update callback.
This struct provides access to frame timing, input state, and other runtime information needed during the game loop.
§Example
ⓘ
game.run(|ctx| {
let dt = ctx.delta_time();
let fps = ctx.fps();
// Move something based on time
position.x += velocity * dt;
});Implementations§
Source§impl GameContext
impl GameContext
Sourcepub fn delta_time(&self) -> f32
pub fn delta_time(&self) -> f32
Sourcepub fn total_time(&self) -> f32
pub fn total_time(&self) -> f32
Returns the total time elapsed since game start in seconds.
Sourcepub fn frame_count(&self) -> u64
pub fn frame_count(&self) -> u64
Returns the current frame number (0-indexed).
Sourcepub fn window_size(&self) -> (u32, u32)
pub fn window_size(&self) -> (u32, u32)
Returns the window dimensions as (width, height).
Sourcepub fn window_width(&self) -> u32
pub fn window_width(&self) -> u32
Returns the window width in pixels.
Sourcepub fn window_height(&self) -> u32
pub fn window_height(&self) -> u32
Returns the window height in pixels.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns true if the game is still running.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GameContext
impl RefUnwindSafe for GameContext
impl Send for GameContext
impl Sync for GameContext
impl Unpin for GameContext
impl UnsafeUnpin for GameContext
impl UnwindSafe for GameContext
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
Mutably borrows from an owned value. Read more
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more