Skip to main content

Scene

Trait Scene 

Source
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§

Source

fn update(&mut self, ctx: &mut Context)

Update logic (called once per frame).

Source

fn render(&mut self, ctx: &mut Context)

Render (called once per frame, after update).

Provided Methods§

Source

fn on_enter(&mut self, _ctx: &mut Context)

Called when the scene is first pushed onto the stack.

Source

fn on_exit(&mut self, _ctx: &mut Context)

Called when the scene is popped off the stack.

Source

fn on_pause(&mut self, _ctx: &mut Context)

Called when the scene below is covered by another scene.

Source

fn on_resume(&mut self, _ctx: &mut Context)

Called when the scene above is popped, revealing this one.

Source

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".

Implementors§