Skip to main content

Scene

Trait Scene 

Source
pub trait Scene {
    // Required methods
    fn on_enter(&mut self);
    fn on_exit(&mut self);
    fn on_update(&mut self, delta_time: f64);
    fn on_render(&self, context: &CanvasRenderingContext2d);
    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_update(&mut self, delta_time: f64)

Called every fixed timestep to update game logic.

§Arguments
  • f64 - The delta time in seconds.
Source

fn on_render(&self, context: &CanvasRenderingContext2d)

Called every render frame to draw the scene.

§Arguments
  • &CanvasRenderingContext2d - The canvas rendering context.
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§