Skip to main content

Game

Struct Game 

Source
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

Source

pub fn new() -> Self

Create a new game with default configuration.

Examples found in repository?
examples/scene_demo.rs (line 111)
106fn main() {
107    let example = SceneDemo {
108        scenes: SceneManager::new(),
109    };
110
111    Game::new()
112        .window_title("game-gem: Scene Demo")
113        .window_size(800, 600)
114        .run(example);
115}
More examples
Hide additional examples
examples/particles.rs (line 107)
102fn main() {
103    let example = ParticlesExample {
104        emitters: Vec::new(),
105    };
106
107    Game::new()
108        .window_title("game-gem: Particles Example")
109        .window_size(800, 600)
110        .clear_color(Color::from_hex("#0A0A1A").unwrap())
111        .run(example);
112}
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}
Source

pub fn window_title(self, title: &str) -> Self

Set the window title.

Examples found in repository?
examples/scene_demo.rs (line 112)
106fn main() {
107    let example = SceneDemo {
108        scenes: SceneManager::new(),
109    };
110
111    Game::new()
112        .window_title("game-gem: Scene Demo")
113        .window_size(800, 600)
114        .run(example);
115}
More examples
Hide additional examples
examples/particles.rs (line 108)
102fn main() {
103    let example = ParticlesExample {
104        emitters: Vec::new(),
105    };
106
107    Game::new()
108        .window_title("game-gem: Particles Example")
109        .window_size(800, 600)
110        .clear_color(Color::from_hex("#0A0A1A").unwrap())
111        .run(example);
112}
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}
Source

pub fn window_size(self, width: u32, height: u32) -> Self

Set the window size in pixels.

Examples found in repository?
examples/scene_demo.rs (line 113)
106fn main() {
107    let example = SceneDemo {
108        scenes: SceneManager::new(),
109    };
110
111    Game::new()
112        .window_title("game-gem: Scene Demo")
113        .window_size(800, 600)
114        .run(example);
115}
More examples
Hide additional examples
examples/particles.rs (line 109)
102fn main() {
103    let example = ParticlesExample {
104        emitters: Vec::new(),
105    };
106
107    Game::new()
108        .window_title("game-gem: Particles Example")
109        .window_size(800, 600)
110        .clear_color(Color::from_hex("#0A0A1A").unwrap())
111        .run(example);
112}
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}
Source

pub fn resizable(self, resizable: bool) -> Self

Set whether the window is resizable.

Source

pub fn fullscreen(self, fullscreen: bool) -> Self

Set whether to start in fullscreen.

Source

pub fn vsync(self, vsync: bool) -> Self

Set whether to enable vsync.

Source

pub fn msaa(self, samples: u32) -> Self

Set MSAA samples (0 = disabled).

Source

pub fn clear_color(self, color: Color) -> Self

Set the clear/background color.

Examples found in repository?
examples/particles.rs (line 110)
102fn main() {
103    let example = ParticlesExample {
104        emitters: Vec::new(),
105    };
106
107    Game::new()
108        .window_title("game-gem: Particles Example")
109        .window_size(800, 600)
110        .clear_color(Color::from_hex("#0A0A1A").unwrap())
111        .run(example);
112}
More examples
Hide additional 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}
Source

pub fn target_fps(self, fps: u32) -> Self

Set target FPS cap (0 = unlimited).

Source

pub fn min_size(self, w: u32, h: u32) -> Self

Set minimum window size.

Source

pub fn icon(self, path: &str) -> Self

Set the window icon from a file path.

Source

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?
examples/scene_demo.rs (line 114)
106fn main() {
107    let example = SceneDemo {
108        scenes: SceneManager::new(),
109    };
110
111    Game::new()
112        .window_title("game-gem: Scene Demo")
113        .window_size(800, 600)
114        .run(example);
115}
More examples
Hide additional examples
examples/particles.rs (line 111)
102fn main() {
103    let example = ParticlesExample {
104        emitters: Vec::new(),
105    };
106
107    Game::new()
108        .window_title("game-gem: Particles Example")
109        .window_size(800, 600)
110        .clear_color(Color::from_hex("#0A0A1A").unwrap())
111        .run(example);
112}
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§

Source§

impl Default for Game

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.