pub trait Scene: 'static {
// Required method
fn update(&mut self, ctx: &mut Context);
// Provided methods
fn start(&mut self, ctx: &mut Context) { ... }
fn fixed_update(&mut self, ctx: &mut Context) { ... }
fn on_ui(&mut self, event: &UiEvent, ctx: &mut Context) { ... }
fn pause(&mut self, ctx: &mut Context) { ... }
fn resume(&mut self, ctx: &mut Context) { ... }
fn end(&mut self, ctx: &mut Context) { ... }
}Expand description
One screen or state of your game: main menu, a level, the game over screen…
Only Scene::update is required. Scenes are switched with Context::switch_scene,
stacked with Context::push_scene (e.g. a pause screen) and removed with
Context::pop_scene.
Required Methods§
Provided Methods§
Sourcefn start(&mut self, ctx: &mut Context)
fn start(&mut self, ctx: &mut Context)
Called once when the scene becomes active for the first time.
Sourcefn fixed_update(&mut self, ctx: &mut Context)
fn fixed_update(&mut self, ctx: &mut Context)
Called at a fixed rate (60 times per second by default) right after each physics step. Use it for logic that must not depend on the frame rate.
Sourcefn on_ui(&mut self, event: &UiEvent, ctx: &mut Context)
fn on_ui(&mut self, event: &UiEvent, ctx: &mut Context)
Called for every UI event before Scene::update. An alternative to polling
ctx.ui.clicked(...) and friends in update.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".