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

pub trait EventHandler<E> where
    E: Error
{
Show methods fn update(&mut self, _ctx: &mut Context) -> Result<(), E>;
fn draw(&mut self, _ctx: &mut Context) -> Result<(), E>; fn mouse_button_down_event(
        &mut self,
        _ctx: &mut Context,
        _button: MouseButton,
        _x: f32,
        _y: f32
    ) { ... }
fn mouse_button_up_event(
        &mut self,
        _ctx: &mut Context,
        _button: MouseButton,
        _x: f32,
        _y: f32
    ) { ... }
fn mouse_motion_event(
        &mut self,
        _ctx: &mut Context,
        _x: f32,
        _y: f32,
        _dx: f32,
        _dy: f32
    ) { ... }
fn mouse_enter_or_leave(&mut self, _ctx: &mut Context, _entered: bool) { ... }
fn mouse_wheel_event(&mut self, _ctx: &mut Context, _x: f32, _y: f32) { ... }
fn key_down_event(
        &mut self,
        ctx: &mut Context,
        keycode: KeyCode,
        _keymods: KeyMods,
        _repeat: bool
    ) { ... }
fn key_up_event(
        &mut self,
        _ctx: &mut Context,
        _keycode: KeyCode,
        _keymods: KeyMods
    ) { ... }
fn text_input_event(&mut self, _ctx: &mut Context, _character: char) { ... }
fn gamepad_button_down_event(
        &mut self,
        _ctx: &mut Context,
        _btn: Button,
        _id: GamepadId
    ) { ... }
fn gamepad_button_up_event(
        &mut self,
        _ctx: &mut Context,
        _btn: Button,
        _id: GamepadId
    ) { ... }
fn gamepad_axis_event(
        &mut self,
        _ctx: &mut Context,
        _axis: Axis,
        _value: f32,
        _id: GamepadId
    ) { ... }
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: f32, _height: f32) { ... }
fn on_error(
        &mut self,
        _ctx: &mut Context,
        _origin: ErrorOrigin,
        _e: E
    ) -> bool { ... }
}
Expand description

A trait defining event callbacks. This is your primary interface with ggez’s event loop. Implement this trait for a type 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 the escape key is pressed. Just override the methods you want to use.

For the error type simply choose GameError, or something more generic, if your situation requires it.

Required methods

Called upon each logic 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 maybe timer::yield_now().

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.

mouse entered or left window area

The mousewheel was scrolled, vertically (y, positive away from and negative toward the user) or horizontally (x, positive to the right and negative to the left).

A keyboard button was pressed.

The default implementation of this will call ggez::event::quit() when the escape key is pressed. If you override this with your own event handler you have to re-implment that functionality yourself.

A keyboard button was released.

A unicode character was received, usually from keyboard input. This is the intended way of facilitating text input.

A gamepad button was pressed; id identifies which gamepad. Use input::gamepad() to get more info about the gamepad.

A gamepad button was released; id identifies which gamepad. Use input::gamepad() to get more info about the gamepad.

A gamepad axis moved; id identifies which gamepad. Use input::gamepad() to get more info about the gamepad.

Called when the window is shown or hidden.

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

Called when the user resizes the window, or when it is resized via graphics::set_mode().

Something went wrong, causing a GameError. If this returns true, the error was fatal, so the event loop ends, aborting the game.

Implementors