The initial state to set.
Whether this is the first frame of the current state.
Number of seconds in the current state.
Return to the previous state (if there is one).
Get the current state.
Whether the current state is the one provided.
State to check for.
Whether the current state is one of the provided states.
Array of possible states.
Set the current state and store the previous state to allow going back.
The new state to change to.
Update the state.
Should be called in parent object's update function.
Delta time since last update.
Tracks state as provided, and provides information on status of the current state. Also allows transitioning to a prior state from a temporary state (e.g. a pause dialog back to game play).
Example
enum GameState { Ready, Playing, Paused, GameOver } // In the constructor of whatever needs state. this.state = new State<GameState>(GameState.Ready) // In the update of the scene/object/whatever. this.state.update(dt) switch (this.state) { case GameState.Ready: if (this.state.first) { console.log('First frame of this state') } // Go to Playing state after 1.5 seconds if (this.state.time > 1.5) { this.state.set(GameState.Playing) } break default: console.log(this.state.get()) }