Trait ggez::event::EventHandler [] [src]

pub trait EventHandler {
    fn update(&mut self, ctx: &mut Context, dt: Duration) -> GameResult<()>;
    fn draw(&mut self, ctx: &mut Context) -> GameResult<()>;

    fn mouse_button_down_event(
        &mut self,
        _button: MouseButton,
        _x: i32,
        _y: i32
    ) { ... } fn mouse_button_up_event(&mut self, _button: MouseButton, _x: i32, _y: i32) { ... } fn mouse_motion_event(
        &mut self,
        _state: MouseState,
        _x: i32,
        _y: i32,
        _xrel: i32,
        _yrel: i32
    ) { ... } fn mouse_wheel_event(&mut self, _x: i32, _y: i32) { ... } fn key_down_event(&mut self, _keycode: Keycode, _keymod: Mod, _repeat: bool) { ... } fn key_up_event(&mut self, _keycode: Keycode, _keymod: Mod, _repeat: bool) { ... } fn controller_button_down_event(&mut self, _btn: Button, _instance_id: i32) { ... } fn controller_button_up_event(&mut self, _btn: Button, _instance_id: i32) { ... } fn controller_axis_event(
        &mut self,
        _axis: Axis,
        _value: i16,
        _instance_id: i32
    ) { ... } fn focus_event(&mut self, _gained: bool) { ... } fn quit_event(&mut self) -> bool { ... } }

A trait defining event callbacks; your primary interface with ggez's event loop. Have a type implement this trait and override at least the update() and draw() methods, then pass it to event::run() to run the game's mainloop.

The default event handlers do nothing, apart from key_down_event(), which will by default exit the game if escape is pressed. Just override the methods you want to do things with.

Required Methods

Called upon each physics update to the game. This should be where the game's logic takes place.

Called to do the drawing of your game. You probably want to start this with graphics::clear() and end it with graphics::present() and timer::sleep_until_next_frame()

Provided Methods

Called upon a quit event. If it returns true, the game does not exit.

Implementors