[−][src]Struct tetra::Context
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]
S: State,
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]
S: State,
F: FnOnce(&mut Context) -> Result<S>,
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
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Same for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn is_in_subset(&self) -> bool
unsafe fn to_subset_unchecked(&self) -> SS
fn from_subset(element: &SS) -> SP
impl<T> SetParameter for T
fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
T: Parameter<Self>,
T: Parameter<Self>,
Sets value
as a parameter of self
.