Trait ggez::event::EventHandler [−][src]
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
fn update(&mut self, _ctx: &mut Context) -> GameResult
[src]
Called upon each logic update to the game. This should be where the game's logic takes place.
fn draw(&mut self, _ctx: &mut Context) -> GameResult
[src]
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
fn mouse_button_down_event(
&mut self,
_ctx: &mut Context,
_button: MouseButton,
_x: f32,
_y: f32
)
[src]
&mut self,
_ctx: &mut Context,
_button: MouseButton,
_x: f32,
_y: f32
)
A mouse button was pressed
fn mouse_button_up_event(
&mut self,
_ctx: &mut Context,
_button: MouseButton,
_x: f32,
_y: f32
)
[src]
&mut self,
_ctx: &mut Context,
_button: MouseButton,
_x: f32,
_y: f32
)
A mouse button was released
fn mouse_motion_event(
&mut self,
_ctx: &mut Context,
_x: f32,
_y: f32,
_dx: f32,
_dy: f32
)
[src]
&mut self,
_ctx: &mut Context,
_x: f32,
_y: f32,
_dx: f32,
_dy: f32
)
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.
fn mouse_enter_or_leave(&mut self, _ctx: &mut Context, _entered: bool)
[src]
mouse entered or left window area
fn mouse_wheel_event(&mut self, _ctx: &mut Context, _x: f32, _y: f32)
[src]
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).
fn key_down_event(
&mut self,
ctx: &mut Context,
keycode: KeyCode,
_keymods: KeyMods,
_repeat: bool
)
[src]
&mut self,
ctx: &mut Context,
keycode: KeyCode,
_keymods: KeyMods,
_repeat: bool
)
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.
fn key_up_event(
&mut self,
_ctx: &mut Context,
_keycode: KeyCode,
_keymods: KeyMods
)
[src]
&mut self,
_ctx: &mut Context,
_keycode: KeyCode,
_keymods: KeyMods
)
A keyboard button was released.
fn text_input_event(&mut self, _ctx: &mut Context, _character: char)
[src]
A unicode character was received, usually from keyboard input. This is the intended way of facilitating text input.
fn gamepad_button_down_event(
&mut self,
_ctx: &mut Context,
_btn: Button,
_id: GamepadId
)
[src]
&mut self,
_ctx: &mut Context,
_btn: Button,
_id: GamepadId
)
A gamepad button was pressed; id
identifies which gamepad.
Use input::gamepad()
to get more info about
the gamepad.
fn gamepad_button_up_event(
&mut self,
_ctx: &mut Context,
_btn: Button,
_id: GamepadId
)
[src]
&mut self,
_ctx: &mut Context,
_btn: Button,
_id: GamepadId
)
A gamepad button was released; id
identifies which gamepad.
Use input::gamepad()
to get more info about
the gamepad.
fn gamepad_axis_event(
&mut self,
_ctx: &mut Context,
_axis: Axis,
_value: f32,
_id: GamepadId
)
[src]
&mut self,
_ctx: &mut Context,
_axis: Axis,
_value: f32,
_id: GamepadId
)
A gamepad axis moved; id
identifies which gamepad.
Use input::gamepad()
to get more info about
the gamepad.
fn focus_event(&mut self, _ctx: &mut Context, _gained: bool)
[src]
Called when the window is shown or hidden.
fn quit_event(&mut self, _ctx: &mut Context) -> bool
[src]
Called upon a quit event. If it returns true, the game does not exit (the quit event is cancelled).
fn resize_event(&mut self, _ctx: &mut Context, _width: f32, _height: f32)
[src]
Called when the user resizes the window, or when it is resized
via graphics::set_mode()
.