pub struct Context { /* fields omitted */ }
A struct containing all of the 'global' state within the framework.
Runs the game using the provided State
implementation.
If the State
returns an error from update
or draw
, the game will stop
running and this method will return the error.
struct GameState;
impl State for GameState { }
fn main() -> tetra::Result {
ContextBuilder::default().build()?.run(&mut GameState)
}
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.
If the State
returns an error from update
or draw
, the game will stop
running and this method will return the error.
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)
}
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
impl<SS, SP> SupersetOf for SP where SS: SubsetOf<SP>, | |
The inverse inclusion map: attempts to construct self
from the equivalent element of its superset. Read more
Checks if self
is actually part of its subset T
(and can be converted to it).
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
The inclusion map: converts self
to the equivalent element of its superset.
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
.