Incorporating the state manager

While it's not quite time for fanfare, excitement is definitely in order because we can finally put our brand new StateManager class to work! The Game class header modification is a good start:

...
#include "StateManager.h"
...
class Game{
public:
    ...
    void LateUpdate();
private:
    ...
    StateManager m_stateManager;
};

Sticking a new data member to the Game class and adding a new method for late updating are all the adjustments that need to be made in the header. Let's adjust the Game constructor to initialize the state manager:

Game::Game(): m_window("Chapter 5", sf::Vector2u(800, 600)), m_stateManager(&m_context) { ... m_context.m_wind = &m_window; m_context.m_eventManager = m_window.GetEventManager(); m_stateManager.SwitchTo(StateType::Intro); ...

Get SFML Game Development By Example 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.