Struct ggez::game::Game
[−]
[src]
pub struct Game<'a, S: GameState> { /* fields omitted */ }
The Game
struct takes an object you define that
implements the GameState
trait
and does the actual work of running a gameloop,
passing events to your handlers, and all that stuff.
Methods
impl<'a, S: GameState + 'static> Game<'a, S>
[src]
fn new(id: &str, default_config: Conf) -> GameResult<Game<'a, S>>
Creates a new Game
with the given default config
(which will be used if there is no config file).
It will initialize a hardware context and call the load()
method of
the given GameState
type to create a new GameState
.
The id
field is a unique identifier for your game that will
be used to create a save directory to write files to.
fn replace_state(&mut self, state: S)
Replaces the gamestate with the given one without having to re-initialize the hardware context.
fn reload_state(&mut self) -> GameResult<()>
Re-creates a fresh GameState
using the existing one's ::load()
method.
fn replace_state_with<F>(&mut self, f: &F) -> GameResult<()> where F: Fn(&mut Context, &Conf) -> GameResult<S>
Calls the given function to create a new gamestate, and replaces the current one with it.
fn run(&mut self) -> GameResult<()>
Runs the game's mainloop.
Continues until a Quit
event is created, for instance
via Context::quit()