pub trait GameState {
// Required methods
fn update(&mut self, ctx: &mut Context);
fn render(&mut self, ctx: &mut Context);
// Provided methods
fn on_enter(&mut self, _ctx: &mut Context) { ... }
fn on_exit(&mut self, _ctx: &mut Context) { ... }
fn fixed_update(&mut self, _ctx: &mut Context) { ... }
}Expand description
The main game state trait. Implement this for your game.
The engine calls these methods every frame in order:
on_enter(once, when the game starts)fixed_update(zero or more times, if fixed timestep is enabled)update(once per frame)render(once per frame)
To add scene management, use crate::scene::SceneManager inside your game state.
Required Methods§
Provided Methods§
Sourcefn on_enter(&mut self, _ctx: &mut Context)
fn on_enter(&mut self, _ctx: &mut Context)
Called once when the game starts (after window creation).
Sourcefn fixed_update(&mut self, _ctx: &mut Context)
fn fixed_update(&mut self, _ctx: &mut Context)
Fixed-rate update (for physics, networking, etc.). Called zero or more times per frame at the fixed timestep rate.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".