pub trait Scene: SceneAsAny + 'static {
// 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 on_pause(&mut self, _ctx: &mut Context) { ... }
fn on_resume(&mut self, _ctx: &mut Context) { ... }
fn handle_event(&mut self, _ctx: &mut Context, _event: &SceneEvent) { ... }
}Expand description
A scene is a self-contained game state (menu, gameplay, pause screen, etc.).
Implement this trait for each major game state. The scene manager handles transitions automatically.
Required Methods§
Provided Methods§
Sourcefn on_enter(&mut self, _ctx: &mut Context)
fn on_enter(&mut self, _ctx: &mut Context)
Called when the scene is first pushed onto the stack.
Sourcefn on_pause(&mut self, _ctx: &mut Context)
fn on_pause(&mut self, _ctx: &mut Context)
Called when the scene below is covered by another scene.
Sourcefn on_resume(&mut self, _ctx: &mut Context)
fn on_resume(&mut self, _ctx: &mut Context)
Called when the scene above is popped, revealing this one.
Sourcefn handle_event(&mut self, _ctx: &mut Context, _event: &SceneEvent)
fn handle_event(&mut self, _ctx: &mut Context, _event: &SceneEvent)
Handle window events (optional override).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".