Trait ggez::game::GameState
[−]
[src]
pub trait GameState { fn load(ctx: &mut Context, conf: &Conf) -> GameResult<Self> where Self: Sized; 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: Option<Keycode>,
_keymod: Mod,
_repeat: bool) { ... } fn key_up_event(&mut self,
_keycode: Option<Keycode>,
_keymod: Mod,
_repeat: bool) { ... } fn focus_event(&mut self, _gained: bool) { ... } fn quit_event(&mut self) -> bool { ... } }
A trait for defining a game state.
Implement load()
, update()
and draw()
callbacks on this trait
and create a Game
object using your gamestate type.
You may also implement the *_event
callbacks if you wish to handle
those events.
The default event handlers do nothing, apart from key_down_event()
,
which should by default exit the game if escape is pressed.
(Once we work around some event bugs in rust-sdl2.)
Required Methods
fn load(ctx: &mut Context, conf: &Conf) -> GameResult<Self> where Self: Sized
Called to initially create your GameState
object
after all hardware initialization has been done.
It is handed a Context
to load resources from,
and the Conf
object that has either been loaded
from your resources/conf.toml
file or the default
that has been provided to Game::new()
if no conf
file exists.
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)
_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: Option<Keycode>,
_keymod: Mod,
_repeat: bool)
_keycode: Option<Keycode>,
_keymod: Mod,
_repeat: bool)
fn key_up_event(&mut self,
_keycode: Option<Keycode>,
_keymod: Mod,
_repeat: bool)
_keycode: Option<Keycode>,
_keymod: Mod,
_repeat: bool)
fn focus_event(&mut self, _gained: bool)
fn quit_event(&mut self) -> bool
Called upon a quit event. If it returns true, the game does not exit.