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 { ... } 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
fn update(&mut self, ctx: &mut Context, dt: Duration) -> GameResult<()>
Called upon each physics update to the game. This should be where the game's logic takes place.
fn draw(&mut self, ctx: &mut Context) -> GameResult<()>
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
fn mouse_motion_event(
&mut self,
_state: MouseState,
_x: i32,
_y: i32,
_xrel: i32,
_yrel: i32
)
&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_axis_event(&mut self, _axis: Axis, _value: i16, _instance_id: i32)
fn focus_event(&mut self, _gained: bool)
Called when the window is shown or hidden.
fn quit_event(&mut self) -> bool
Called upon a quit event. If it returns true, the game does not exit.
fn resize_event(&mut self, _ctx: &mut Context, _width: u32, _height: u32)
Called when the user resizes the window.
Is not called when you resize it yourself with
graphics::set_mode()
though.