O'Reilly logo

SFML Game Development By Example by Raimondas Pupius

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required