pub struct Game { /* private fields */ }Expand description
The game builder. Configure your game and run it.
§Example
use game_gem::prelude::*;
struct MyGame;
impl GameState for MyGame {
fn update(&mut self, ctx: &mut Context) {
if ctx.input.keyboard.is_pressed(KeyCode::Escape) { ctx.quit(); }
}
fn render(&mut self, ctx: &mut Context) {
ctx.graphics.clear(Color::BLACK);
}
}
fn main() {
Game::new()
.window_title("Hello game-gem!")
.window_size(1024, 768)
.clear_color(Color::from_hex("#1A1A2E").unwrap())
.target_fps(60)
.run(MyGame);
}Implementations§
Source§impl Game
impl Game
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new game with default configuration.
Examples found in repository?
More examples
examples/basics.rs (line 154)
147fn main() {
148 let example = BasicsExample {
149 ball: BouncingBall::new(),
150 hue: 0.0,
151 click_count: 0,
152 };
153
154 Game::new()
155 .window_title("game-gem: Basics Example")
156 .window_size(800, 600)
157 .clear_color(Color::from_hex("#0F0F23").unwrap())
158 .run(example);
159}Sourcepub fn window_title(self, title: &str) -> Self
pub fn window_title(self, title: &str) -> Self
Set the window title.
Examples found in repository?
More examples
examples/basics.rs (line 155)
147fn main() {
148 let example = BasicsExample {
149 ball: BouncingBall::new(),
150 hue: 0.0,
151 click_count: 0,
152 };
153
154 Game::new()
155 .window_title("game-gem: Basics Example")
156 .window_size(800, 600)
157 .clear_color(Color::from_hex("#0F0F23").unwrap())
158 .run(example);
159}Sourcepub fn window_size(self, width: u32, height: u32) -> Self
pub fn window_size(self, width: u32, height: u32) -> Self
Set the window size in pixels.
Examples found in repository?
More examples
examples/basics.rs (line 156)
147fn main() {
148 let example = BasicsExample {
149 ball: BouncingBall::new(),
150 hue: 0.0,
151 click_count: 0,
152 };
153
154 Game::new()
155 .window_title("game-gem: Basics Example")
156 .window_size(800, 600)
157 .clear_color(Color::from_hex("#0F0F23").unwrap())
158 .run(example);
159}Sourcepub fn fullscreen(self, fullscreen: bool) -> Self
pub fn fullscreen(self, fullscreen: bool) -> Self
Set whether to start in fullscreen.
Sourcepub fn clear_color(self, color: Color) -> Self
pub fn clear_color(self, color: Color) -> Self
Set the clear/background color.
Examples found in repository?
More examples
examples/basics.rs (line 157)
147fn main() {
148 let example = BasicsExample {
149 ball: BouncingBall::new(),
150 hue: 0.0,
151 click_count: 0,
152 };
153
154 Game::new()
155 .window_title("game-gem: Basics Example")
156 .window_size(800, 600)
157 .clear_color(Color::from_hex("#0F0F23").unwrap())
158 .run(example);
159}Sourcepub fn target_fps(self, fps: u32) -> Self
pub fn target_fps(self, fps: u32) -> Self
Set target FPS cap (0 = unlimited).
Sourcepub fn run<S: GameState>(self, state: S)
pub fn run<S: GameState>(self, state: S)
Run the game with the given game state.
This is the main entry point. It creates the window, initializes the context, and runs the game loop until the game exits.
Examples found in repository?
More examples
examples/basics.rs (line 158)
147fn main() {
148 let example = BasicsExample {
149 ball: BouncingBall::new(),
150 hue: 0.0,
151 click_count: 0,
152 };
153
154 Game::new()
155 .window_title("game-gem: Basics Example")
156 .window_size(800, 600)
157 .clear_color(Color::from_hex("#0F0F23").unwrap())
158 .run(example);
159}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Game
impl RefUnwindSafe for Game
impl Send for Game
impl Sync for Game
impl Unpin for Game
impl UnsafeUnpin for Game
impl UnwindSafe for Game
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more