Struct anima_engine::game::GameLoop [] [src]

pub struct GameLoop<T: Game> {
    pub game: T,
}

A struct that helps you create a very simple game loop.

Examples

pub struct MyGame;

impl Game for MyGame {
    fn update(&self, dt: Duration) -> bool {
        // Update game state.
        // Return `false` when game needs to stop.
        false
    }
}

GameLoop::new(MyGame).run();

Fields

game

Methods

impl<T: Game> GameLoop<T>

fn new(game: T) -> GameLoop<T>

Creates a GameLoop.

Examples

pub struct MyGame;

impl Game for MyGame {
    fn update(&self, dt: Duration) -> bool {
        // Update game state.
        // Return `false` when game needs to stop.
        false
    }
}

GameLoop::new(MyGame);

fn run(&self)

Runs GameLoop's Game in a loop while feeding the time between frames to the Game's update.

Examples

pub struct MyGame;

impl Game for MyGame {
    fn update(&self, dt: Duration) -> bool {
        // Update game state.
        // Return `false` when game needs to stop.
        false
    }
}

GameLoop::new(MyGame).run();