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

pub trait EventHandler {
    fn update(&mut self, _ctx: &mut Context) -> GameResult<()>;
fn draw(&mut self, _ctx: &mut Context) -> GameResult<()>; fn mouse_button_down_event(
        &mut self,
        _ctx: &mut Context,
        _button: MouseButton,
        _x: i32,
        _y: i32
    ) { ... }
fn mouse_button_up_event(
        &mut self,
        _ctx: &mut Context,
        _button: MouseButton,
        _x: i32,
        _y: i32
    ) { ... }
fn mouse_motion_event(
        &mut self,
        _ctx: &mut Context,
        _state: MouseState,
        _x: i32,
        _y: i32,
        _xrel: i32,
        _yrel: i32
    ) { ... }
fn mouse_wheel_event(&mut self, _ctx: &mut Context, _x: i32, _y: i32) { ... }
fn key_down_event(
        &mut self,
        ctx: &mut Context,
        keycode: Keycode,
        _keymod: Mod,
        _repeat: bool
    ) { ... }
fn key_up_event(
        &mut self,
        _ctx: &mut Context,
        _keycode: Keycode,
        _keymod: Mod,
        _repeat: bool
    ) { ... }
fn controller_button_down_event(
        &mut self,
        _ctx: &mut Context,
        _btn: Button,
        _instance_id: i32
    ) { ... }
fn controller_button_up_event(
        &mut self,
        _ctx: &mut Context,
        _btn: Button,
        _instance_id: i32
    ) { ... }
fn controller_axis_event(
        &mut self,
        _ctx: &mut Context,
        _axis: Axis,
        _value: i16,
        _instance_id: i32
    ) { ... }
fn focus_event(&mut self, _ctx: &mut Context, _gained: bool) { ... }
fn quit_event(&mut self, _ctx: &mut Context) -> bool { ... }
fn resize_event(&mut self, _ctx: &mut Context, _width: u32, _height: u32) { ... } }

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

A mouse button was pressed

A mouse button was released

The mouse was moved; it provides both absolute x and y coordinates in the window, and relative x and y coordinates compared to its last position.

The mousewheel was clicked.

A keyboard button was pressed.

A keyboard button was released.

A controller button was pressed; instance_id identifies which controller.

A controller button was released.

A controller axis moved.

Called when the window is shown or hidden.

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

Called when the user resizes the window. Is not called when you resize it yourself with graphics::set_mode() though.

Implementors