pub trait EventHandler {
// Required methods
fn update(&self, game: &mut Game) -> Result<()>;
fn draw(&self, game: &mut Game) -> Result<()>;
// Provided methods
fn key_down_event(
&self,
_game: &mut Game,
_timestamp: u64,
_window_id: u32,
_keycode: Option<Keycode>,
_scancode: Option<Scancode>,
_keymod: Mod,
_repeat: bool,
_which: u32,
_raw: u16,
) -> Result<()> { ... }
fn key_up_event(
&self,
_game: &mut Game,
_timestamp: u64,
_window_id: u32,
_keycode: Option<Keycode>,
_scancode: Option<Scancode>,
_keymod: Mod,
_repeat: bool,
_which: u32,
_raw: u16,
) -> Result<()> { ... }
fn mouse_motion_event(
&self,
_game: &mut Game,
_timestamp: u64,
_window_id: u32,
_which: u32,
_mousestate: MouseState,
_x: f32,
_y: f32,
_xrel: f32,
_yrel: f32,
) -> Result<()> { ... }
fn mouse_button_down_event(
&self,
_game: &mut Game,
_timestamp: u64,
_window_id: u32,
_which: u32,
_mouse_btn: MouseButton,
_clicks: u8,
_x: f32,
_y: f32,
) -> Result<()> { ... }
fn mouse_button_up_event(
&self,
_game: &mut Game,
_timestamp: u64,
_window_id: u32,
_which: u32,
_mouse_btn: MouseButton,
_clicks: u8,
_x: f32,
_y: f32,
) -> Result<()> { ... }
fn mouse_wheel_event(
&self,
_game: &mut Game,
_timestamp: u64,
_window_id: u32,
_which: u32,
_x: f32,
_y: f32,
_direction: MouseWheelDirection,
_mouse_x: f32,
_mouse_y: f32,
) -> Result<()> { ... }
}Expand description
Trait that must be implemented by user’s game state struct
updateis called to advance game state (physics, AI, input processing).drawis called to render the current state usinggame.graphics.
Both return anyhow::Result<()>