[][src]Struct tetra::Context

pub struct Context { /* fields omitted */ }

A struct containing all of the 'global' state within the framework.

Methods

impl Context[src]

pub fn run<S>(&mut self, state: &mut S) -> Result where
    S: State
[src]

Runs the game using the provided State implementation.

Errors

If the State returns an error from update or draw, the game will stop running and this method will return the error.

Examples

struct GameState;

impl State for GameState { }

fn main() -> tetra::Result {
   ContextBuilder::default().build()?.run(&mut GameState)
}

pub fn run_with<S, F>(&mut self, init: F) -> Result where
    S: State,
    F: FnOnce(&mut Context) -> Result<S>, 
[src]

Constructs an implementation of State using the given closure, and then runs it.

This is mainly handy when chaining methods, as it allows you to call your State constructor without breaking the chain.

Errors

If the State returns an error from update or draw, the game will stop running and this method will return the error.

Examples

struct GameState {
    texture: Texture,
}

impl GameState {
    fn new(ctx: &mut Context) -> tetra::Result<GameState> {
        Ok(GameState {
            texture: Texture::new(ctx, "./examples/resources/player.png")?,
        })
    }
}

impl State for GameState { }

fn main() -> tetra::Result {
   ContextBuilder::default().build()?.run_with(GameState::new)
}

Auto Trait Implementations

impl !Send for Context

impl !Sync for Context

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> SetParameter for T

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
    T: Parameter<Self>, 

Sets value as a parameter of self.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>,