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

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: 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_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 controller_button_down_event(
        &mut self,
        _ctx: &mut Context,
        _btn: Button,
        _id: usize
    ) { ... }
fn controller_button_up_event(
        &mut self,
        _ctx: &mut Context,
        _btn: Button,
        _id: usize
    ) { ... }
fn controller_axis_event(
        &mut self,
        _ctx: &mut Context,
        _axis: Axis,
        _value: f32,
        _id: usize
    ) { ... }
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) { ... } }

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.

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().

Loading content...

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 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.

A keyboard button was released.

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

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

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

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

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().

Loading content...

Implementors

Loading content...