Struct Game

Source
pub struct Game<State, Update> { /* private fields */ }
Expand description

Tells the engine how to run a game.

This is returned by baba::game and you can modify settings with the available methods below.

Implementations§

Source§

impl<State, Update: Fn(&mut State)> Game<State, Update>

Source

pub fn scale_mode(self, scale_mode: ScaleMode) -> Self

Sets the default scaling for textures. Defaults to nearest scaling.

Source

pub fn framerate(self, framerate: Framerate) -> Self

Sets the framerate limit. Defaults to 1x the display refresh rate.

Source

pub fn vsync(self) -> Self

Enable vsync, reducing tearing at the cost of some latency.

Source

pub fn viewport(self, viewport: Viewport) -> Self

Sets a viewport for the screen.

Examples found in repository?
examples/soko.rs (line 5)
3fn main() -> baba::Result {
4    baba::game("SOKOBAN", Soko::update)
5        .viewport(Viewport::new(32 * 7, 32 * 7))
6        .run_with(Soko::new)
7}
Source

pub fn window_title(self, title: impl Into<String>) -> Self

Sets the window title. This defaults to the name given to game or run.

Source

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

Sets the window size. Defaults to 800x600.

Source

pub fn settings(self, settings: Settings) -> Self

Set the engine settings.

This will override any other methods.

Source

pub fn window(self, settings: WindowSettings) -> Self

Sets all window settings.

Overrides any other window_* methods.

Source

pub fn run(self) -> Result
where State: Default,

Runs the game, using Default for the state.

Source

pub fn run_with(self, init: impl FnOnce() -> State) -> Result

Runs the game, using a initializer function.

Examples found in repository?
examples/soko.rs (line 6)
3fn main() -> baba::Result {
4    baba::game("SOKOBAN", Soko::update)
5        .viewport(Viewport::new(32 * 7, 32 * 7))
6        .run_with(Soko::new)
7}

Auto Trait Implementations§

§

impl<State, Update> Freeze for Game<State, Update>
where Update: Freeze,

§

impl<State, Update> RefUnwindSafe for Game<State, Update>
where Update: RefUnwindSafe, State: RefUnwindSafe,

§

impl<State, Update> Send for Game<State, Update>
where Update: Send, State: Send,

§

impl<State, Update> Sync for Game<State, Update>
where Update: Sync, State: Sync,

§

impl<State, Update> Unpin for Game<State, Update>
where Update: Unpin, State: Unpin,

§

impl<State, Update> UnwindSafe for Game<State, Update>
where Update: UnwindSafe, State: UnwindSafe,

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.