Trait tetra::State

source ·
pub trait State {
    fn update(&mut self, ctx: &mut Context);
    fn draw(&mut self, ctx: &mut Context, dt: f64);
}
Expand description

A trait representing a type that contains game state and provides logic for updating it and drawing it to the screen. This is where you’ll write your game logic!

The game will update at a fixed time step (defaulting to 60fps), and draw as fast as it is allowed to (depending on CPU/vsync settings). This allows for deterministic updates even at varying framerates, but may require you to do some interpolation in order to make things look smooth.

See Fix Your Timestep for more info.

Required Methods§

Called when it is time for the game to update, at the interval specified by the context’s tick rate.

Called when it is time for the game to be drawn.

As drawing will not necessarily be in step with updating, the dt argument is provided - this will be a number between 0 and 1, specifying how far through the current tick you are.

For example, if the player is meant to move 16 pixels per frame, and the current dt is 0.5, you should draw them 8 pixels along.

Implementors§