Integrating the stack in the Application class
Since we have now more states than the game itself, we create a new class Application
that controls input, logic updates, and rendering. Having a ready StateStack
implementation waiting to be used, it is time to promote it into the Application
class. We will plug our new state architecture into our Application
class and then start using it!
First, we add the mStateStack
member variable to Application
. We register all the states in an own method:
void Application::registerStates() { mStateStack.registerState<TitleState>(States::Title); mStateStack.registerState<MenuState>(States::Menu); mStateStack.registerState<GameState>(States::Game); mStateStack.registerState<PauseState>(States::Pause); }
Now there are a few more things we must care about for a full integration of our state architecture:
Feeding it with events in the
Application::processInput()
function:while (mWindow.pollEvent(event)) { mStateStack...