Skip to main content

Scene

Trait Scene 

Source
pub trait Scene: Lifecycle {
    // Required methods
    fn on_enter(&mut self);
    fn on_exit(&mut self);
    fn on_render(&self, draw_list: &mut DrawList);
    fn name(&self) -> &str;
}
Expand description

The base trait for all game scenes.

A scene encapsulates a self-contained portion of the game world, managing its own game objects, resources, and update logic.

Required Methods§

Source

fn on_enter(&mut self)

Called once when this scene becomes the active scene.

Source

fn on_exit(&mut self)

Called once when this scene is being replaced or removed.

Source

fn on_render(&self, draw_list: &mut DrawList)

Called every render frame to record the scene’s draw commands.

Instead of drawing immediately, the scene pushes DrawCommands into the provided DrawList; the engine replays the whole list once per frame in a single batched pass.

§Arguments
  • &mut DrawList - The draw list to record commands into.
Source

fn name(&self) -> &str

Returns the name of this scene for identification.

§Returns
  • &str - The scene name.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§