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 ...

Get SFML Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.