Skip to main content

Scene

Trait Scene 

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

Source

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

Called every frame. Put your game logic here.

Provided Methods§

Source

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

Called once when the scene becomes active for the first time.

Source

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.

Source

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.

Source

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

Called when another scene is pushed on top of this one.

Source

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

Called when this scene is on top again after the scene above was popped.

Source

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

Called when the scene is removed (popped, switched away, or the game quits).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§