Skip to main content

GameState

Trait GameState 

Source
pub trait GameState {
    // 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 fixed_update(&mut self, _ctx: &mut Context) { ... }
}
Expand description

The main game state trait. Implement this for your game.

The engine calls these methods every frame in order:

  1. on_enter (once, when the game starts)
  2. fixed_update (zero or more times, if fixed timestep is enabled)
  3. update (once per frame)
  4. render (once per frame)

To add scene management, use crate::scene::SceneManager inside your game state.

Required Methods§

Source

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

Main update logic. Called once per frame.

Source

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

Render the game. Called once per frame, after update.

Provided Methods§

Source

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

Called once when the game starts (after window creation).

Source

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

Called when the game is about to exit.

Source

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

Fixed-rate update (for physics, networking, etc.). Called zero or more times per frame at the fixed timestep rate.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§