[][src]Trait crystal_engine::Game

pub trait Game {
    fn init(state: &mut GameState) -> Self;
fn update(&mut self, state: &mut GameState); fn can_shutdown(&mut self, _state: &mut GameState) -> bool { ... }
fn event(&mut self, _state: &mut GameState, _event: &WindowEvent) { ... }
fn keydown(&mut self, _state: &mut GameState, _key: VirtualKeyCode) { ... }
fn keyup(&mut self, _state: &mut GameState, _key: VirtualKeyCode) { ... } }

The entry point of the game implementation.

In your game you will have to implement this trait for your own Game object. See the main module documentation for an example.

Required methods

fn init(state: &mut GameState) -> Self

Create a new instance of the game. This will be called exactly once, whenever the game window is created.

fn update(&mut self, state: &mut GameState)

Update the game. This will be called every frame. Use this to implement your game logic.

Loading content...

Provided methods

fn can_shutdown(&mut self, _state: &mut GameState) -> bool

Checks if the game can shut down. This is called when a player tries to close the window by clicking X or pressing alt+f4

fn event(&mut self, _state: &mut GameState, _event: &WindowEvent)

Triggered when a winit event is received.

fn keydown(&mut self, _state: &mut GameState, _key: VirtualKeyCode)

Triggered when a key is pressed.

Note that the GameState.keyboard is updated before this method is called. This means that state.keyboard.is_pressed(key) will always return true.

fn keyup(&mut self, _state: &mut GameState, _key: VirtualKeyCode)

Triggered when a key is released.

Note that the GameState.keyboard is updated before this method is called. This means that state.keyboard.is_pressed(key) will always return false.

Loading content...

Implementors

Loading content...