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); }
Naturally, the first thing we do is create the context that will be used by all of the states and pass it into the constructor of the state manager. We then begin the "domino effect...